我想将谷歌地图移动到一个城市。用户可以从选择框中选择城市名称。我需要所选城市的经纬度。当用户选择城市时,我必须找到它的经纬度。 我正在使用此代码来移动 map
var center = new google.maps.LatLng(lat,long);
map.panTo(center);
最佳答案
我用下面的代码尝试了
var address = city_name;
geocoder.geocode({'address': address},function(results, status){
if (status === google.maps.GeocoderStatus.OK)
{
map.setCenter(results[0].geometry.location);
}else
{
alert('Geocode was not successful for the following reason: ' + status);
}
});
关于javascript - 我想获取城市名称的经纬度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35943421/