作者slamgundam (Rick)
看板Ajax
標題[問題] 關於 google map v3 api的 dragend問題
時間Sat Jun 13 13:58:35 2015
想請問大家關於 google map v3 api的 dragend傾聽事件內透過Geocoder() API的座標位
置取得formatted_address的住址字串,然後要傳回給輸入欄位。
現在重點是當我移動Marker時,我無法把住址字串傳回給輸入欄位。
目前是有透過$watch來監聽.....但是一樣沒辦法把住址傳回給輸入欄位。
有透過console.log()來觀察,是有變化的。
我是用 IONIC Framework
手機排版...不好意思...
謝謝大家 ><"
這是在view內
<div class="list list-inset">
<label class="item item-input">
<input type="text" placeholder="Pickup location" ng-model-options="{ updateOn
:'default blur' }" ng-model="pickupLocation" ng-blur="pickupLocationEvent(pick
upLocation)" />
</label>
</div>
----------------------------------------------
這是在controller內
google.maps.event.addListener(pickupLocationMarker, 'dragend', function(evt){
console.log("lat : "+evt.latLng.lat().toFixed(6)+"\nlng :
"+evt.latLng.lng().toFixed(6));
var myLatlng = new google.maps.LatLng(evt.latLng.lat(), ev
t.latLng.lng());
geocoder.geocode({'latLng': myLatlng}, function(results, s
tatus) {
if (status == google.maps.GeocoderStatus.OK) {
if(results[1]) {
dragedAddress = results[1].formatted_address;
infowindow.setContent(dragedAddress);
infowindow.open(map, pickupLocationMarker);
//$scope.pickupLocationAddress = dragedAddress;
$scope.$watch(function () {
$scope.pickupLocation = dragedAddress;
console.log($scope.pickupLocation)
});
} else {
alert('No results found');
}
} else {
alert('Geocoder failed due to: ' + status);
}
});
});
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 218.164.9.117
※ 文章網址: https://webptt.com/m.aspx?n=bbs/Ajax/M.1434175118.A.359.html