i have created the following function to show and address in JS:
function showMapForm(idDiv, divWidth, divHeight, idLat, idLng) {
document.getElementById(idDiv).style.width = divWidth+'px';
document.getElementById(idDiv).style.height = divHeight+'px';
if (document.getElementById(idLat).value=='' && document.getElementById(idLng).value=='') {
//Paris
iniLat = 48.85455;
iniLng = 2.358627;
} else {
iniLat = document.getElementById(idLat).value;
iniLng = document.getElementById(idLng).value;
}
var latlng = new google.maps.LatLng(iniLat, iniLng);
var myOptions = {
zoom: 15,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById(idDiv), myOptions);
marker = new google.maps.Marker({
position: new google.maps.LatLng(iniLat, iniLng),
map: map
});
google.maps.event.addListener(map, 'click', function(eve) {
marker.setPosition(eve.latLng);
document.getElementById(idLat).value = marker.getPosition().lat();
document.getElementById(idLng).value = marker.getPosition().lng();
});
}
as you can see it requires the id of a div, the width and height desired and the id of the hidden fields where I stock the latitude and longitude, if those values aren't present it will use the latitude and longitude of Paris. What i would like to do is to improve this function so it can accept a string value with an address like "Saint Joseph Street No. 45, Paris" and put a marker if it finds the address.
My question is: do you know if there's a way to get a latitude and longitude from a search string using the google maps API? (the first occurrence will do it)