gpt4 book ai didi

调用 Android Phonegap : Google Map marker not immediately removed when marker. setMap(null)

转载 作者:行者123 更新时间:2023-11-29 18:06:31 25 4
gpt4 key购买 nike

当我使用 marker.setMap(null) 删除标记时,它一直可见,直到我缩小,此时 Google map 将其删除。

在与 Windows 上的 Chrome 相同的 HTML 页面上删除后,标记不可见。

似乎在删除标记后 map 没有正确刷新。

有问题的代码(标记应该在 5 秒后消失):

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<script type="text/javascript" charset="utf-8" src="cordova-2.1.0.js"></script>
<script type="text/javascript" charset="utf-8" src="jquery-1.8.2.min.js"></script>
<style type="text/css">
* {
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}
html { height: 100%; }
body { height: 100%; margin: 0; padding: 0 }
#map_canvas { height: 100% }
</style>
<script type="text/javascript"
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAQ7L1PL7pQzSuDfv9kTL_qE4Cp0wy8Oo8&sensor=true">
</script>
<script type="text/javascript">
var theMap = null;
function initialize() {
var mapOptions = {
zoom: 10,
center: new google.maps.LatLng(37.7749295, -122.4194155),
disableDefaultUI: true,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
theMap = new google.maps.Map(document.getElementById('map_canvas'),
mapOptions);
navigator.geolocation.getCurrentPosition(
function (position) {
// successfully load position
var lat = position.coords.latitude;
var long = position.coords.longitude;
theMap.setCenter(new google.maps.LatLng(lat, long), 21);
},
function (fail) {
console.error("Failed to load GPS coordinates");
}
);
var marker;
function addMarker(itemid, lat, lon) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(lat, lon),
map: theMap
});
}
addMarker('pokemon', 37.42841, -122.16960);
setTimeout(function() {marker.setMap(null);}, 5000);
}


</script>
</head>
<body onload="initialize();">
<div id="map_canvas" style="width:100%; height:100%; top:0px; z-index: 10"/>
</body>
</html>

最佳答案

我认为,这与这里的问题相同:Google Maps API v3 in PhoneGap: markers not drawing properly after move

尝试将 optimized: false 属性设置为标记:

new google.maps.Marker({
map: map,
optimized: false,
clickable: true
});

这应该可以解决它!

关于调用 Android Phonegap : Google Map marker not immediately removed when marker. setMap(null),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13150760/

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