- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 google map api v3
的新手。我已经建立了一个带有 2 个标记的像样的谷歌地图,但是当我使用 google.maps.latlngBounds
时,它返回给我一个错误
invalidValueError:setCenter:不是 LatLng 或 LatLngLiteral 对象
。
我该如何解决这个问题?我只想让我的 map 围绕这些标记居中。
function initialize() {
var myLatlng = new google.maps.LatLng(-25.363882,131.044922);
var myLatlng2 = new google.maps.LatLng(-25.573688, 132.567212);
var mapOptions = {
center: myLatlng,
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
try {
var map = new google.maps.Map(document.getElementById("map-canvas"),
mapOptions);
var marker = new google.maps.Marker({
position: myLatlng
});
var marker2 = new google.maps.Marker({
position: myLatlng2
});
trackerMarkerArray.push(marker);
trackerMarkerArray.push(marker2);
var latlngbound = new google.maps.LatLngBounds ();
for (var i = 0; i<trackerMarkerArray.length; i++){
trackerMarkerArray[i].setMap(map);
latlngbound.extend(trackerMarkerArray[i].position);
}
//render new map and center around group of marker
map.setCenter(latlngbound);
map.fitBounds(latlngbound);
} catch (err){
alert(err);
}
}
google.maps.event.addDomListener(window, 'load', initialize);
最佳答案
将 map “拟合”到添加到 google.maps.LatLngBounds 的一组标记对象使用 map.fitBounds(bounds),而不是 map.setCenter()。
关于javascript - 无效值错误 : setCenter : not a LatLng or LatLngLiteral Object,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23003104/
所以我的代码遇到了问题,我尝试从从数据库下载的变量设置谷歌街景位置。它的数据库和 php 端可以工作,但是当我尝试将其分配给“panorama.setPosition(prizeLocation);”
我是 google map api v3 的新手。我已经建立了一个带有 2 个标记的像样的谷歌地图,但是当我使用 google.maps.latlngBounds 时,它返回给我一个错误 invali
我尝试使用 GWT Maps API V3 3.8.1 创建一个演示。我的演示只是显示了 API 版本 3 的谷歌地图 public class MyGoogleMap implements IsWi
我开始了解 PHP 和 JavaScript,将它们混合在 HTML 中并使用 Google Maps API(版本 3)。 我想出了如何“放置”各种标记,但控制台会抛出错误: " Uncaught
这个问题在这里已经有了答案: How to fix Uncaught InvalidValueError: setPosition: not a LatLng or LatLngLiteral: i
我正在使用 Angular 谷歌地图来设置当前位置和 agm-direction 来设置方向。下面是代码,我遇到了上述错误。 最佳答案 这可能是因为当您调用 getDirections() 时,您的组
我正在使用 GWT(2.61 版)和 gwt-maps(3.8.0 版)努力通过 GWT 显示 Google map 。 基础似乎可行,但现在我正在尝试运行 gwt-maps zip 附带的 City
function initAutocomplete() { var lat=document.getElementById('lat').value; var lng=document
我正在尝试将我的 googlemaps v2 功能移植到 v3。 但不知何故我陷入了一个奇怪的错误,我找不到我做错了什么。 Error : Uncaught InvalidValueError: se
尝试使用 Google Maps API 初始化 map 。以数字形式输入中心的纬度和经度。收到一条错误,指出它们不是数字。 var map; // Variable used to create n
我正在编写一个基本的 JavaScript 程序,用于查找两个邮政编码之间的距离。代码如下: index.html
我是一名优秀的程序员,十分优秀!