休息标记位置 + 信息窗口位置
Rest the marker position + info window position
我在谷歌地图中设置信息窗口的位置时遇到问题。
我知道这听起来有点担心,但我的愿望是,如果纬度,lng 为 0,0,我想将标记放在美国地图的中心,并将信息窗口的位置停留在同一位置。
希望有人能帮助我...
map = new google.maps.Map(document.getElementById("map-canvas"));
//I'm getting from an object that I'm looping on it coordinates 0,0
var myLatLng = new google.maps.LatLng(0, 0);
// Create the marker on the map
var marker = new google.maps.Marker({
position: myLatLng,
map: map
});
// Check if the LatLng are 0,0 - hide the marker redefine the position of the marker + map position.
if (myLatLng == "0,0") {
var CenterLatLng = new google.maps.LatLng(39.828127, -98.579404);
marker.setVisible(false);
marker.setPosition(CenterLatLng);
map.setCenter(new google.maps.LatLng(39.828127, -98.579404));
}
var contentString = '<div id="content">'+
'<div id="siteNotice">'+
'</div>'+
'<h1 id="firstHeading" class="firstHeading">Uluru</h1>'+
'<div id="bodyContent">'+
'<p><b>Uluru</b>, also referred to as <b>Ayers Rock</b>, is a large ' +
'sandstone rock formation in the southern part of the '+
'Northern Territory, central Australia. It lies 335 km (208 mi) '+
'south west of the nearest large town, Alice Springs; 450 km '+
'(280 mi) by road. Kata Tjuta and Uluru are the two major '+
'features of the Uluru - Kata Tjuta National Park. Uluru is '+
'sacred to the Pitjantjatjara and Yankunytjatjara, the '+
'Aboriginal people of the area. It has many springs, waterholes, '+
'rock caves and ancient paintings. Uluru is listed as a World '+
'Heritage Site.</p>'+
'<p>Attribution: Uluru, <a href="https://en.wikipedia.org/w/index.php?title=Uluru&oldid=297882194">'+
'https://en.wikipedia.org/w/index.php?title=Uluru</a> '+
'(last visited June 22, 2009).</p>'+
'</div>'+
'</div>';
var infowindow = new google.maps.InfoWindow({
content: contentString
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map,marker); // When The info window is open its grabbing the correct value that I defined in the above but it's opening it somewhere else on the map
});
要检查 google.maps.LatLng 值,请使用 google.maps.LatLng 方法 .equals, not (myLatLng == "0,0")
工作小提琴
相关文章:
- 谷歌地图API-信息窗口显示谷歌位置API信息
- 更改信息窗口的位置显示在谷歌地图API v3中
- 谷歌地图API地理位置文本搜索地点详细信息
- 谷歌地图偏移标记/信息窗口位置(panTo/setCenter)
- 点的访问器's修改海拔高度的位置标记信息
- 是否可以在javascript中基于地理位置获取街道详细信息
- 地图位置带有照片和其他详细信息的详细信息
- 如何使用html/html5中的用户输入获取完整的地理位置详细信息
- 休息标记位置 + 信息窗口位置
- 在谷歌地图中设置信息窗口位置
- 包含 Mongodb 中位置信息的文档
- 无法使用 JavaScript 获取位置信息
- 将地图位置信息从PHP传递到javascript,以便与Google地图v3api一起使用
- 试图在领英与javascript api的第一次连接上拉位置信息
- 在Google Maps API的标记上显示位置信息
- 如何获取用户的浏览器详细信息、IP地址和位置信息
- Mvc4:传递位置信息到javascript变量的地理位置
- 触发谷歌地图位置信息窗口
- cookie、localStorage和jquery数据用于存储大小和位置信息
- Google 如何在未经用户许可的情况下获取当前位置信息