开发者

possible to highlight a section of a street?

I need to highlight a section of a street between two intersections. I have found a similar question which was asked more than a year ago (see here) which says that Google, Bing, etc. do not provide street data through their APIs. Does anyone know if anything has changed in the APIs, and whether I can get street location latitude/lon开发者_Python百科gitude data from somewhere now?


I have done this in API V2, but it should not be to difficult to rewrite it for V3.

Have a look at this website http://www.fvs.de/anfahrt.php (in German) and click the "Weg in Karte zeigen" buttons ("show way in map") in the sections below the map. Each button highlights another street line in the map.

It is basically done by using directions object of Google Maps to plot a route between two arbitrary street points in the map (e.g. your two intersections). The points must be encoded with their LatLng coordinates. Here is a code example (as said this is API V2):

function initMap() {  // called by page onload event
  if (GBrowserIsCompatible()) {
    // Display the map, with some controls and set the initial location 
    gMap = new GMap2(document.getElementById("map_canvas"));
    gMap.addControl(new GLargeMapControl());
    // ...
    gMap.setCenter(GLatLng(49.238326, 6.977761), 15);

    // init directions object and attach listener to handle route loads from function highliteRoute()
    gDir = new GDirections();
    gPoly = null;
    GEvent.addListener(gDir, 'load', function(){
      gPoly = gDir.getPolyline();
      gMap.addOverlay(gPoly);

      // zoom & pan to poly        
      var polyBds  = gPoly.getBounds();
      var polyZoom = gMap.getBoundsZoomLevel(polyBds);
      gMap.setZoom(polyZoom);
      gMap.panTo(polyBds.getCenter());
    });
  }
}

function highliteRoute(){
  if(gPoly!=null)  gPoly.hide();
  gDir.load('from: 49.313530,6.969109 to: 49.238326,6.977761', {getPolyline:true});
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜