Google Maps Geocode Showing Wrong Address
I have locations stored within a database, and I am looping through them and putting markers down for each location (mix of JS and Razor) on Google Maps (API v3). The code I am usi
Solution 1:
Try using the full address for your geolocator request, and setting the region to UK (if all of your addresses are in the UK), this should narrow down the search a bit
functionplaceMarkerForAddress(address, city, postcode, country) {
var fullAddress = address + ', ' + city + ', ' + postcode + ', ' + country;
geocoder.geocode( { 'address': fullAddress, 'region':'UK'}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location,
title: fullAddress
});
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
});
}
And when you get the updated position you need to centre the map as well as move the marker
functionupdateMarker( marker, latitude, longitude, label ){
// Update the position.var pos=new google.maps.LatLng(latitude,longitude);
// move the marker
marker.setPosition(pos);
// centre the map
marker.getMap().setCenter(pos);
// Update the title if it was provided.if (label){
marker.setTitle( label );
}
}
Post a Comment for "Google Maps Geocode Showing Wrong Address"