[英]Using google map GDirections with address
I need to use the google map directions to show the directions between two addresses. 我需要使用谷歌地图方向来显示两个地址之间的方向。
How can i show the google map using addresses? 如何使用地址显示谷歌地图?
Also, I have the source and destination addresses (no latitude and longitude), how can I show the directions between the address using jquery? 另外,我有源地址和目的地址(没有纬度和经度),如何使用jquery显示地址之间的方向?
That's very easy: 这很容易:
var map = new GMap2(document.getElementById('map_canvas'));
var directions = new GDirections(map);
directions.load('from: London, UK to: Glasgow, UK');
Screenshot: 截图:
UPDATE: 更新:
Using the v3 API is a bit more verbose, but still straightforward: 使用v3 API有点冗长,但仍然很简单:
var map = new google.maps.Map(document.getElementById('map_canvas'), {
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var directionsService = new google.maps.DirectionsService();
var directionsDisplay = new google.maps.DirectionsRenderer();
directionsDisplay.setMap(map);
var request = {
origin: 'London, UK',
destination: 'Glasgow, UK',
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.