如何轻松地将javascript版本迁移到谷歌地图的新版本?

时间:2012-12-02 11:28:17

标签: javascript google-maps deprecated

多年前,我很难用谷歌标记为我的网站做谷歌地图。 我正在为paypal投入ssl,我只是检查并看到地图不适用于htts: 所以我进入谷歌地图寻找解决方案,看到javascript已被删除,他们建议升级到版本3。 是否有一个简单的方法或一些教程,因为我忙于尝试集成paypal,这是最后一次并不容易。有什么提示吗?

这就是我的地图:

function createMarker(point,html) {
    var marker = new GMarker(point);
    GEvent.addListener(marker, "click", enter code herefunction() {
      marker.openInfoWindowHtml(html);
    });
    return marker;
  }

  // Display the map, with some controls and set the initial location 
  var map = new GMap2(document.getElementById("map"));
  map.addControl(new GLargeMapControl());
  map.addControl(new GMapTypeControl());
  map.setCenter(new GLatLng(36.51308543049258, -4.886341094970703), 13);

  // Set up three markers with info windows  

  var point = new GLatLng(36.50856685143835, -4.866085052490234);
  var marker = createMarker(point,'<div style="width:240px">Text here<a href="link here">Link<\/a><\/div>')
  map.addOverlay(marker);

由于

1 个答案:

答案 0 :(得分:1)

使用v2 referencemigration table创建文本文件:

v2                v3
GMap2             google.maps.Map
GLatLng           google.maps.LatLng
GInfoWindow       google.maps.InfoWindow
GMapOptions       google.map.MapOptions
G_API_VERSION     google.maps.version
GPolyStyleOptions google.maps.PolygonOptions or google.maps.PolylineOptions

然后以某种方式运行查找/替换:

   for func in `cat deprecated.txt`
     do
      grep -R $func /path/to/src
   done

<强>参考