您可以通过以下方式收听中心更改,您只需更新您的视图:
google.maps.event.addListener(map, "dragend", function() {
console.log(map.getCenter().toUrlValue());
});
当前主要使用的解决方案是仅在单击时调出 InfoWindow,我一直需要它,就像在 Uber 上一样,所以我什至将 InfoWindow 替换为仅 css 的解决方案,使用 Ionic 更新视图的正常角度路线
HTML:
<ion-content >
<div id="map" data-tap-disabled="true">
</div>
<div id="centerInfoBubble">
<span>{{locationCtrl.coordinates}}</span>
</div>
<div id="centerMarker"></div>
</div>
</ion-content>
CSS:
#map {
width: 100%;
height: 100%;
}
#centerInfoBubble {
position: absolute;
/*center the marker*/
top: 38%;
left: 22.5%;
z-index: 1;
width: 50%;
height: 6%;
border-radius: 20px;
border: 1px solid #111;
background-color: #444444;
color: #fff;
padding: 0.5% 5%;
cursor: pointer;
}
#centerMarker {
position: absolute;
/*url of the marker*/
background: url(http://maps.gstatic.com/mapfiles/markers2/marker.png) no-repeat;
/*center the marker*/
top: 45%;
left: 45%;
z-index: 1;
height: 10%;
width: 10%;
cursor: pointer;
}
控制器:
myModule.controller('LocationCtrl',['$scope','$cordovaGeolocation',function($scope,$cordovaGeolocation){
$scope.locationCtrl = {
coordinates : null
};
var options = {timeout: 10000, enableHighAccuracy: true};
var marker;
$cordovaGeolocation.getCurrentPosition(options).then(function(position){
var latLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
var mapOptions = {
center : latLng,
zoom : 16,
mapTypeId : google.maps.MapTypeId.ROADMAP,
mapTypeControl : false,
streetViewControl : false,
zoomControl : false
};
$scope.map = new google.maps.Map(document.getElementById("map"), mapOptions);
$scope.locationCtrl.coordinates = $scope.map.getCenter().toUrlValue();
google.maps.event.addListener($scope.map, "dragend", function() {
$scope.locationCtrl.coordinates = $scope.map.getCenter().toUrlValue();
$scope.$apply();
});
}, function(error){
console.log("Could not get location");
});
}]);
我不知道这是否存在性能问题,但在设备上看起来相当流畅,希望它可以帮助某人