Google Map API V3 geocoder not showing the correct place
I am upgrading my codes from Google Map API V2 to V3. In V2, I used GlocalSearch to get the latitude and longitude for the given address.
In V3, I saw google.maps.Geocoder() and try to get the similar detail. However, the lat & long given by the V3 function is not accurate.
Pls see the following screenshot here:
My codes for V3 are as follow:
var geocoder = new google.maps.Geocoder();
function codeAddress(address) {
if (geocoder)
{
address = add开发者_StackOverflow社区ress + ", UK";
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var latlng = results[0].geometry.location;
addMarker(latlng); //Adding Marker here
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
}
Is there better way to get the accurate result in API V3? Thanks.
Log the value of the location property and check if the coordinates are correct.
Post the addMarker method code.
Another option is to call the web service which will result results in either JSON or XML format and then you can formulate these results to get the desired location. There are plenty of examples on google maps v3 documentation
精彩评论