0

I am working on a migration project from google maps V2 to V3 and can't get the following working.

<!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>

Actually I don't want to use the options parameter in the new google.maps.Map function. I want to center the map using map.center function.

4

1 回答 1

1

这是错误的:

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

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

map.setCenter(new google.maps.LatLng(51.508742,-0.120850));
于 2013-04-24T12:29:08.010 回答