最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Using google map GDirections with address - Stack Overflow

programmeradmin2浏览0评论

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?

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?

Share Improve this question edited Jul 12, 2010 at 10:51 Daniel Vassallo 345k72 gold badges512 silver badges446 bronze badges asked Jul 12, 2010 at 10:09 PrasadPrasad 59.5k65 gold badges153 silver badges201 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 9

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:

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);
  }
});
发布评论