javascript geocode latlng variable
JAVASCRIPT
Im sure this a very simple problem.
I am modifying the line below and want to replace (53, 0) with a variable. However, the variable that is created called 'result', is equal to '(34, 2)', ie it already ha开发者_JS百科s the brackets around it.
center: new google.maps.LatLng.(53, 0)
i have tried
center: new google.maps.LatLng.(result)
center: new google.maps.LatLng.result
center: new google.maps.LatLng.({result})
and it no working!
FULL CODE
var geocoder = new google.maps.Geocoder();
if (geocoder) {
geocoder.geocode({ 'address': address }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
window.result = results[0].geometry.location;
alert(result);
}
else {
alert('nothing');
}
});
}
function load() {
map = new google.maps.Map(document.getElementById("map"), {
center: new google.maps.LatLng.(53, 0),
zoom: 10,
mapTypeId: 'roadmap',
mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU}
});
}
For reference, alert(result) returns
(53.8622017, -2.405405999999971)
you putting . after the LatLng the correct way to create the latlng object was try this way
center:new google.maps.LatLng(-34.397, 150.644);
here . define the package level and the last latLng was class
like google is top level in that maps and in that LatLng was defined.
So the LatLng has 2 parameter (latitude and longitude)
Try new google.maps.LatLng(result[0], result[1])? Please post where the 'result' variable is created.
why don't you set your map center in the response
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
}
精彩评论