可以突出显示街道的一部分吗?

发布于 2024-12-08 23:59:30 字数 240 浏览 2 评论 0原文

我需要突出显示两个十字路口之间的街道部分。我发现了一年多前提出的类似问题(请参阅此处< /a>)表示 Google、Bing 等不通过其 API 提供街道数据。有谁知道 API 中是否有任何更改,以及我现在是否可以从某处获取街道位置纬度/经度数据?

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/longitude data from somewhere now?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

丢了幸福的猪 2024-12-15 23:59:30

我已经在 API V2 中做到了这一点,但为 V3 重写它应该不难。

看看这个网站http://www.fvs.de/anfahrt.php(在德语),然后单击地图下方部分中的“Weg in Karte zeigen”按钮(“在地图中显示路线”)。每个按钮都会突出显示地图中的另一条街道线。

它基本上是通过使用 Google 地图的方向对象来绘制地图中两个任意街道点(例如两个十字路口)之间的路线来完成的。这些点必须使用其 LatLng 坐标进行编码。这是一个代码示例(据说这是 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});
}

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});
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文