Google maps 如何从Google Map API的参数变量中获取城市名称
我正在使用此函数:Google maps 如何从Google Map API的参数变量中获取城市名称,google-maps,Google Maps,我正在使用此函数:getDirection(glat、glon、acity)使用此函数,我必须绘制一条从城市到glat和glong[纬度和经度]位置的路线。我完成了所有工作,但我不知道如何将变量acity设置为原点 var directionsService = new google.maps.DirectionsService(); var directionsDisplay = new google.maps.DirectionsRenderer(); var default_latitud
getDirection(glat、glon、acity)
使用此函数,我必须绘制一条从城市到glat和glong[纬度和经度]位置的路线。我完成了所有工作,但我不知道如何将变量acity设置为原点
var directionsService = new google.maps.DirectionsService();
var directionsDisplay = new google.maps.DirectionsRenderer();
var default_latitude=22.5936840;//12.9715987;
var default_longitude=78.962880;//77.5945627;
var myOptions =
{
center: new google.maps.LatLng(default_latitude,default_longitude),
zoom: 4,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("mapp"),myOptions);
var latlng=new google.maps.LatLng(glat,glon);
$('#mapDiv1').modal({closeClass: "mapCloseImg1"});
directionsDisplay.setMap(map);
directionsDisplay.setPanel(document.getElementById("panel"));
var request = {
origin: [WANT TO PUT ACITY AS ORIGIN BUT DONT KNOW HOW]
destination:latlng,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
}
您需要的是使用反向地理代码。请参阅此文档:只需使用
origin:acity
@red\u警报:origin和destination也接受字符串,directionsService将自动进行地理编码。@Dr.Molle非常感谢,先生,,,我认为这将是一个很长的过程