我刚刚将代码从v2更新到了v3。所有东西都在工作,但这里的函数map.fitBounds();是我的示例代码。
var geocoder = new google.maps.Geocoder(); geocoder.geocode( { 'address': 'your address'}, >function(results, status) { if (status == google.maps.GeocoderStatus.OK) { var newPoint = new google.maps.LatLng(results[0].geometry.location.lat(), >results[0].geometry.location.lng()); markerBounds.extend(newPoint); var marker = new google.maps.Marker({ map: map, position: results[0].geometry.location }); } else { alert('Geocode was not successful for the following reason: ' + status); } }); map.fitBounds(markerBounds); }
我发现这段代码看起来很好,但是这里的fitBounds()不能工作。下文的答复中提到了所需的改变。
发布于 2013-09-21 16:49:48
在这种情况下,我们必须编写这样的代码
markerBounds.extend(newPoint); map.fitBounds(markerBounds);//在功能上,而不是在最后
这对我很有帮助,希望对你也有帮助。
https://stackoverflow.com/questions/18930703
复制相似问题