ウェブアプリケーションで角度ng-mapを使用しています。私は選択されたユーザーのアドレスを取得し、そこにマーカーを置いてからズームインする機能を構築しました。しかし、setTimeout
を私のマーカーに集中させないと、私のアプリケーションのどこにでもgeolocateを使用しないにもかかわらず、マップは自動的に私のgeolocationにスナップします。誰がどのように/なぜこれが起こるか知っていますか?angularjs ng-mapは一見無意識のうちに自分の位置に自動的にフォーカスします
コントローラー:
NgMap.getMap({id:'map'}).then(function(map) {
console.log('map', map);
vm.map = map;
//GEOCODER
var patientLat;
var patientLon;
var geocoder = new google.maps.Geocoder();
geocoder.geocode({ "address": vm.myData.addressHome + ' ' + vm.myData.addressCity + ' ' + vm.myData.state + ' ' + 'USA'}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK && results.length > 0) {
var location = results[0].geometry.location;
patientLat = location.lat();
patientLon = location.lng();
console.log("the patient is located at " + patientLat + " " + patientLon);
vm.patientLocation = [
{
"patientLat" : patientLat
, "patientLon" : patientLon
}
]
setTimeout(function(){
patientPos(patientLat, patientLon);
}, 2000) <---------- here is the timeout i need
}
});
});
function patientPos(patientLat, patientLon) {
console.log(patientLat);
console.log(patientLon);
var bounds2 = new google.maps.LatLngBounds();
var latLng2 = new google.maps.LatLng(patientLat, patientLon);
bounds2.extend(latLng2);
vm.map.fitBounds(bounds2);
vm.map.setZoom(10);
}
HTML
<ng-map
id="map"
scrollwheel="false"
>
<marker
ng-repeat="q in vm.patientLocation"
position="{{q.patientLat}}, {{q.patientLon}}"
icon="{
url:'app/assets/img/patienticon.png',
scaledSize:[30,30]
}"
id="lkj98"
></marker>
<marker
ng-repeat="p in locatorGridData track by $index"
position="{{p.Location.Lat}}, {{p.Location.Long}}"
icon="{
url:'app/assets/img/placeholder.png',
scaledSize:[30,30]
}"
id="{{p.id}}"
on-click="vm.showDetail(p)"
class="markers"
></marker>
<shape id="circle" name="circle" centered="true"
stroke-color='#bc1212' stroke-opacity="0.8"stroke-weight="2"
center="current-position" radius={{vm.selectedRadius}} editable="false" ></shape>
<info-window id="infoWindow" visible-on-marker="lkj98yuih">
<div ng-non-bindable="">
<div class="practice-name">{{vm.p.Location.OrgName}}</div>
<div class="name-specialty">{{vm.p.Provider.firstName}} {{vm.p.Provider.lastName}}, {{vm.p.Provider.speciality}}</div>
<div class="other-text-for-info-window">
{{vm.p.Location.Address1}}<br>
{{vm.p.Location.City}}, {{vm.p.Location.State}}<br>
{{vm.p.Location.Zip}}
</div>
</div>
</info-window>
</ng-map>