有可能突出一段街道? [英] possible to highlight a section of a street?

查看:201
本文介绍了有可能突出一段街道?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要突出显示两个交叉点之间的一段街道。我发现了一年多以前问过的类似问题(请参阅此处),它表示Google,Bing等不通过其API提供街道数据。有谁知道API中是否有任何变化,以及我现在是否可以从某处获得街道位置纬度/经度数据?

我已经在API V2中完成了这个工作,但是对V3重写它不应该很困难。



看看这个网站 http:// www.fvs.de/anfahrt.php (德语),然后点击地图下方的Weg in Karte zeigen按钮(show way in map)。每个按钮突出显示地图中的另一条街道线。

它基本上是通过使用Google Maps的地图对象来绘制地图中任意两个街点之间的路线(例如您的两个交点)。这些点必须用它们的LatLng坐标进行编码。这里是一个代码示例(如上所述,这是API V2):

 函数initMap(){//由page onload事件调用
if(GBrowserIsCompatible()){
//显示地图,带有一些控件并设置初始位置
gMap = new GMap2(document.getElementById(map_canvas));
gMap.addControl(new GLargeMapControl());
// ...
gMap.setCenter(GLatLng(49.238326,6.977761),15);

//初始化方向对象并附加侦听器来处理来自函数的路由加载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());
});



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


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?

解决方案

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});
}

这篇关于有可能突出一段街道?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆