【发布时间】:2015-08-28 07:53:24
【问题描述】:
需要获取动态位置图钉而不是移动到我从 html5 地理定位中获得的位置。我尝试了其他一些事情,但图钉不断生成重复项。删除图钉也有用。
var map = null;
var p = 0;
var x = document.getElementById("notice");
$(document).ready(function(){
getLocation();
watchPosition();
});
function watchPosition() {
//map options
var mapOptions = {
credentials: "key here",
mapTypeId: Microsoft.Maps.MapTypeId.road,
zoom: 19
};
//map initialization
map = new Microsoft.Maps.Map(document.getElementById('mapDiv'), mapOptions);
}
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.watchPosition(success, error, {maximumAge: 5000,
enableHighAccuracy: true});
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function error(err) {
x.innerHTML = err.toString();
}
function success(position) {
x.innerHTML = "Latitude: " + position.coords.latitude + "<br>Longitude: " + position.coords.longitude;
var pos = new Microsoft.Maps.Location(position.coords.latitude, position.coords.longitude);
//console.log(pos);
p++;
console.log(p);
//infobox
var offsetInfo = new Microsoft.Maps.Point(0, 30);
var infoboxOptions = { title: "Location Information", description: "This is your current location.", offset: offsetInfo };
var callout = new Microsoft.Maps.Infobox(pos, infoboxOptions);
//pushpin
var offsetPin = new Microsoft.Maps.Point(0, 5);
var pushpinOptions = {text : '1', visible: true, textOffset: offsetPin};
var pushpin = new Microsoft.Maps.Pushpin(pos, pushpinOptions);
map.setView({center:pos});
if (p <= 1) {
map.entities.push(pushpin);
} else {
pushpin.setLocation(pos);
console.log(toString(pushpin.getLocation()));
}
}
【问题讨论】:
-
您的语言不清楚,并且您没有将其连接到您的代码。请阅读this并采取行动。
标签: javascript geolocation bing-maps