gpt4 book ai didi

javascript - Google map 错误 - 纬度/经度无效?

转载 作者:行者123 更新时间:2023-12-02 17:19:25 27 4
gpt4 key购买 nike

我有以下代码:

<script src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>

<div class="row">
<div class="col-md-6" id="googleMap" style="height:500px;"></div>
</div>

<script>
function initialize() {
var mapProp = {
center: new google.maps.LatLng(44.6656, -83.5753),
zoom: 10,
mapTypeId: google.maps.MapTypeId.ROADMAP
};

var map = new google.maps.Map(document.getElementById("googleMap")
,mapProp);

var marker = new google.maps.Marker({
position: mapProp,
});

marker.setMap(map);
}

google.maps.event.addDomListener(window, 'load', initialize);
</script>

map 显示正常,但我无法添加标记。我收到以下错误:

setPosition: not a LatLng or LatLngLiteral: in property lat: not a number

我不明白纬度和经度如何无效,因为生成的 map 显示了正确的位置。但没有标记。

最佳答案

标记的 position 属性应为 LatLng 类型:

<script src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>

<div class="row">
<div class="col-md-6" id="googleMap" style="height:500px;"></div>
</div>

<script>
function initialize() {

var cord = new google.maps.LatLng(41.6656, -83.5753);

var mapProp = {
center: cord,
zoom: 10,
mapTypeId: google.maps.MapTypeId.ROADMAP
};

var map = new google.maps.Map(document.getElementById("googleMap")
,mapProp);

var marker = new google.maps.Marker({
position: cord,
});

marker.setMap(map);
}

google.maps.event.addDomListener(window, 'load', initialize);
</script>

http://jsfiddle.net/5am3V/

关于javascript - Google map 错误 - 纬度/经度无效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24101143/

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