【问题标题】:Change google maps api v2 to v3将谷歌地图 api v2 更改为 v3
【发布时间】:2015-06-17 19:03:05
【问题描述】:

我的网站上运行了一个 gmap api,它刚刚停止显示地图。我不知道发生了什么,而且我没有创建它由以前的开发人员创建的代码。必须有一个解决方案,请帮助。我已经提供了之前开发者创建的功能代码。

//XXXX: openInfoWindowHtml
/*--------------------------------------------------*/
/*	GOOGLE MAP FUNCTIONS
/*--------------------------------------------------*/

var map, agentMarkers, reoMarkers, officeMarker, currentMarker, bounds, agentIcon, reoIcon, officeIcon;
var infoWindow = new google.maps.InfoWindow();

function initAgentMap(lat, lng) {
	lat = isNaN(lat) || lat === null ? 37.4419 : lat;
	lng = isNaN(lng) || lat === null ? -122.1419 : lng;
	map = new google.maps.Map(document.getElementById("gmap"), {
        center : new google.maps.LatLng(lat, lng),
        zoom: 13,
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        zoomControlOptions : {
	        style : google.maps.ZoomControlStyle.SMALL
	    }
	});
	agentMarkers = [];
	reoMarkers = [];
	currentMarker = null;
	bounds = new google.maps.LatLngBounds();

	var baseIcon = {
	    size : new google.maps.Size(29,25),
	    anchor : new google.maps.Point(15,25),
	    imageMap : [0, 0, 22, 0, 22, 25, 0, 25]
	};

	agentIcon = {
	    size : baseIcon.size,
	    anchor : baseIcon.anchor,
	    imageMap : baseIcon.imageMap,
	    url : "/images/icon_redbook.png"
    };

	reoIcon = {
	    size : baseIcon.size,
	    anchor : baseIcon.anchor,
	    imageMap : baseIcon.imageMap,
	    url : "/images/icon_reo.png"
	};

	officeIcon = {
        size : baseIcon.size,
        anchor : baseIcon.anchor,
        imageMap : baseIcon.imageMap,
        url : "/images/icon_office.png"
	};
}

function plotAgent(lat, long, text, id) {
	var point = new google.maps.LatLng(lat, long);
	var marker = new google.maps.Marker({
	    position : point,
	    icon : agentIcon,
	    anchorPoint : new google.maps.Point(12,0),
	    map : map
	});
	google.maps.event.addListener(marker, "click", function() {
		infoWindow.setContent(text);
		infoWindow.open(map, marker);
	});
	agentMarkers[id] = marker;
	bounds.extend(point);
	return marker;
}

function plotREO(lat, long, text, id) {
	var point = new google.maps.LatLng(lat, long);
	var marker = new google.maps.Marker({
	    position : point,
	    icon : reoIcon,
	    anchorPoint : new google.maps.Point(12,0),
	    map : map
	});
	google.maps.event.addListener(marker, "click", function () {
		infoWindow.setContent(text);
		infoWindow.open(map, marker);
	});
	reoMarkers[id] = marker;
	bounds.extend(point);
	return marker;
}

function plotOffice(lat, long, text) {
	var point = new google.maps.LatLng(lat, long);
	var marker = new google.maps.Marker({
	    position : point,
	    icon : officeIcon,
	    anchorPoint : new google.maps.Point(12,0),
	    map : map
	});
	google.maps.event.addListener(marker, "click", function () {
		infoWindow.setContent(text);
		infoWindow.open(map, marker);
	});
	officeMarker = marker;
	bounds.extend(point);
	return marker;
}

function showAgent(id) {
	if(currentMarker != id){
		currentMarker = id;
		google.maps.event.trigger(agentMarkers[id], "click");
		map.setZoom(11);
		pnt = agentMarkers[id].getPosition();
		pnt2 = new google.maps.LatLng(pnt.lat() + .02 , pnt.lng());
		map.setCenter(pnt2);
	}

}

function showREO(id) {
	if(currentMarker != id){
		currentMarker = id;
		google.maps.event.trigger(reoMarkers[id], "click");
		map.setZoom(11);
		pnt = reoMarkers[id].getPosition();
		pnt2 = new google.maps.LatLng(pnt.lat() + .02 , pnt.lng());
		map.setCenter(pnt2);
	}
}

function showOffice() {
	if(currentMarker != 'office'){
		currentMarker = 'office';
		google.maps.event.trigger(officeMarker, "click");
		map.setZoom(11);
		pnt = officeMarker.getPosition();
		pnt2 = new google.maps.LatLng(pnt.lat() + .02 , pnt.lng());
		map.setCenter(pnt2);
	}
}

我的网站上运行了一个 gmap api,它刚刚停止显示地图。我不知道发生了什么,而且我没有创建它由以前的开发人员创建的代码。必须有一个解决方案,请帮助。我提供了之前开发者创建的功能代码。

【问题讨论】:

  • 你的代码 sn-p 没有运行
  • GMarker.openInfoWindowHtml 是 Google Maps Javascript API v2 方法,在 v3 中不受支持。 Google Maps Javacript API v2 已于 2010 年 5 月 19 日被弃用并关闭,替换为 v3 的包装器,它不应用于新代码。也就是说,您的代码中没有使用它。请修正问题的标题以反映您的实际问题。
  • 好的,你能告诉我代码应该是什么样子吗?谢谢!!
  • 我尝试用 v3 的包装器替换 v2 的包装器。我真的需要一个解决方案。

标签: javascript google-maps google-maps-api-3 hashmap


【解决方案1】:

v2 Maps API 在 2010 年被弃用,最终在 2013 年 11 月被关闭。您将 need to migrate 到 JS Maps API 的 v3。不幸的是,这不是一个完全简单的过程。

【讨论】:

  • 好的,您能给我提供一个如何进行此迁移的链接吗?我只需要知道发生了什么变化以及如何更新我的 v2 Maps API。
  • 我在上面的答案中链接到migration guide。
  • 我已经尝试将代码从 V2 迁移到 V3,但我不确定我缺少什么。有人可以证明我做错了什么吗?
猜你喜欢
  • 1970-01-01
  • 2011-03-25
  • 2011-07-14
  • 2013-02-20
  • 2013-04-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多