gpt4 book ai didi

javascript - 如果 'Accept-Language' 设置为英语以外的语言,则 Google map 中的标记位置错误

转载 作者:行者123 更新时间:2023-11-28 07:22:55 24 4
gpt4 key购买 nike

我的网站使用的是 Google map 。它显示很少的标记并将它们全部显示在屏幕上。如果“Accept-Language”设置为英语,则一切正常。一旦您将“接受语言”更改为其他语言,所有标记都会在 map 上重新排列。无法弄清楚我做错了什么。

<html>
<head lang="en">
<title>GMaps Test</title>
<meta charset="UTF-8">
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js"></script>
<script language="JavaScript" type="text/javascript">
$(document).ready(function () {

var map;

// List of markers
var all_markers = [];

function map_initialize() {
var mapOptions = {
center: { lat: 57.332332, lng: 34.725238},
zoom: 5,
zoomControl: true,
zoomControlOptions: {
style: google.maps.ZoomControlStyle.SMALL
},
disableDefaultUI: true
};
var map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);

// Make an array of the LatLng's of the markers to show
var LatLngList = [
{id: "4", pos: new google.maps.LatLng(55,7569492,37,6416684)},

{id: "3", pos: new google.maps.LatLng(40,790278,-73,959722)},

{id: "7", pos: new google.maps.LatLng(37,8099098,-122,497668)},

{id: "1", pos: new google.maps.LatLng(55,7773455,37,6423385)},
];

// Create a new viewpoint bound
var bounds = new google.maps.LatLngBounds();
// For outputting info
var infowindow = new google.maps.InfoWindow();
// Go through each...
for (var i = 0, LtLgLen = LatLngList.length; i < LtLgLen; i++) {

// Adding marker to the map
var marker = new google.maps.Marker({
position: new google.maps.LatLng(LatLngList[i].pos.lat(), LatLngList[i].pos.lng()),
map: map,
icon: "https://www.google.com/intl/en_us/mapfiles/ms/micons/pink-dot.png"
});

// Storing marker in a list
all_markers.push({id: LatLngList[i].id, marker: marker});

// And increase the bounds to take this point
bounds.extend(LatLngList[i].pos);

// Click handler for the marker
google.maps.event.addListener(marker, 'click', (function (marker, i) {
return function () {
infowindow.setContent('Ololo');
infowindow.open(map, marker);
}
})(marker, i));
}
// Fit these bounds to the map
if(LatLngList.length > 0) map.fitBounds(bounds);
};

google.maps.event.addDomListener(window, 'load', map_initialize);
});

</script>
</head>
<body>
<div id="map-canvas" style="height: 100%; width: 100%; padding: 0; margin: 0"></div>
</body>

</html>

最佳答案

在 javascript 中,小数分隔符是一个点,但您使用逗号

关于javascript - 如果 'Accept-Language' 设置为英语以外的语言,则 Google map 中的标记位置错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30086280/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com