我正在显示带有“跟踪我的位置”按钮的地图。它开始标记用户的位置,但在用户移动时留下一串标记。如何在用户移动时获取单个标记来更新其位置?
<script type="text/javascript">
$( document ).bind( "mobileinit", function() {
$.mobile.allowCrossDomainPages = true;
});
</script>
<script src="../../jquery.mobile.min.js"></script>
<script src="https://maps.googleapis.com/maps/api/js? key=AIzaSyCvtEfhi11SeoL1Osfo8St53JRkasYnTRw&sensor=true"></script>
<script src="../../cordova-2.7.0.js"></script>
<script type="text/javascript">
var map;
var image = "../../bbimages/cycling.png";
$(document).on('pageshow', '#fenlandmap', function(){
$(document).on('click', '#”btnInit”', function(){
navigator.geolocation.watchPosition(onMapSuccess, onMapFailure, {enableHighAccuracy:true,timeout:20000});
});
var latlng = new google.maps.LatLng(51.183244, -115.585399);
var myOptions = {
zoom: 15,
streetViewControl: false,
center: latlng,
mapTypeId: google.maps.MapTypeId.HYBRID
};
map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
var kmlUrl = 'http://www.sites.google.com/site/skyrokml/kml/FenlandTrail.kml';
var kmlOptions = {
suppressInfoWindows: false,
preserveViewport: true,
map: map
};
var kmlLayer = new google.maps.KmlLayer(kmlUrl, kmlOptions);
});
function onMapSuccess(pos) {
map.setCenter(new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude));
var marker = new google.maps.Marker({
position: map.getCenter(),
icon: image,
map: map,
title: 'Click to zoom'
}); }
function onMapFailure() {
alert('You must have an internet connection to view the maps');
}
</script>
</head>
<body>
<div data-role="page" style="width:100%;height:100%;" id="fenlandmap">
<div data-role="content" style="width:100%;height:100%;" id="map_content">
<div id="map_canvas" style="width:100%; height:448px"></div>
</div><!-- /content -->
<div data-role="footer" data-position="fixed" id="footer" align="center">
<a href="../bbteasyfenlandloop.html" data-role="button" data-direction="reverse"
data-transition="slide"
data-icon="arrow-l">Back</a>
<a href="../../index.html" data-role="button"
data-transition="turn" data-direction="reverse" data-icon="home">Home</a>
<button id=”btnInit” data-icon="star">Track my Position</button>
</div>
</div>
<!-- /page -->
</body>