2
私はこのコードセットを持っていますが、私の現在の位置を取得するたびに私のボタンをクリックすると、地図が中央に配置されます。私の地図を動かさないうちに私の場所を取得することは可能ですか?Googleマップを中央に移動するのを止める方法
google.maps.event.addDomListener(controlText, 'click', function(self)
{
getLocation(self);
});
function getLocation(self)
{
console.log("in get location", self);
let locationOptions =
{
timeout : 60000,
enableHighAccuracy : true
};
navigator.geolocation.getCurrentPosition
(
(position) =>
{
self.curLat = position.coords.latitude;
self.curLong = position.coords.longitude;
console.log("updated position coord:"+self.curLat+","+self.curLong);
self.local = new Storage(LocalStorage);
self.local.set("currLong", self.curLong);
self.local.set("currLat", self.curLat);
map.setCenter(new google.maps.LatLng(self.curLat, self.curLong));
markers = removeMarker(markers);
addMarker(map, markers);
},
(error) => {console.log(error);}, locationOptions
);
};
myLocationMarker = new google.maps.Marker
({
map : map,
icon : image,
animation : google.maps.Animation.DROP,
position : map.getCenter(),
id : 'myLocationMarker'
});
markers.push(myLocationMarker);
私は
map.setCenter(new google.maps.LatLng(self.curLat, self.curLong));
to
var latLng = new google.maps.LatLng(self.curLat, self.curLong);
を変更し、位置のためにそれを使用するaddMarkerにデータを渡すことによって、私の問題を解決しています。
あなたは'位置を削除しようとしたことがありますか? – cjross
こんにちは、私はmap.setCenterを削除してこの問題を解決しました。ありがとう! –