从google maps V2迁移到Version 3

Migration from google maps V2 to Version 3

本文关键字:Version 迁移 V2 google maps      更新时间:2023-09-26

我正在进行从google maps V2到V3的迁移项目,无法获得以下工作

<!DOCTYPE html>
<html>
<head>
<script
src="http://maps.googleapis.com/maps/api/js?key=myApiKey&sensor=false">
</script>
<script>
function initialize()
{
var map=new google.maps.Map(document.getElementById("googleMap"));
map.setCenter(new google.maps.LatLng(51.508742,-0.120850),5);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="googleMap" style="width:500px;height:380px;"></div>
</body>
</html>

实际上我不想在新的google.maps.Map函数中使用options参数。我想使用map将地图居中。中心功能。

这是错误的:

map.setCenter(new google.maps.LatLng(51.508742,-0.120850),5);

setCenter只接受一个参数,即LatLng对象。试试这个:

map.setCenter(new google.maps.LatLng(51.508742,-0.120850));