Kit*_*_HK 7 google-maps google-maps-api-3 angularjs ionic
我正在学习AngularJS和Ionic,我正在将Google Maps API v3添加到我的应用程序中.
这是我的控制器:
$scope.drawMap = function(position) {
$scope.$apply(function() {
$scope.abc.lng = resp.data[0].longit;
$scope.abc.lat = resp.data[0].latit;
$scope.map = {
center: {
latitude: $scope.abc.lat,
longitude: $scope.abc.lng
},
zoom: 17
};
$scope.marker = {
id: 0,
coords: {
latitude: $scope.abc.lat,
longitude: $scope.abc.lng
}
};
$scope.marker.options = {
draggable: false,
labelAnchor: "80 120", //marker position
labelClass: "marker-labels"
};
});
}
navigator.geolocation.watchPosition($scope.drawMap);
$scope.$on('$ionicView.leave', function(){
map.remove();
});
Run Code Online (Sandbox Code Playgroud)
}); })
这是我的HTML:
<ui-gmap-google-map center='map.center' zoom='map.zoom' events="map.markersEvents">
<ui-gmap-marker coords="marker.coords" options="marker.options" idkey="marker.id">
</ui-gmap-marker>
</ui-gmap-google-map>
Run Code Online (Sandbox Code Playgroud)
指令也是:
starter.directive('googleMap', function(){
return {
templateUrl:"templates/google-map.html",
link: function(scope, ele, attrs){
}
}
})
Run Code Online (Sandbox Code Playgroud)
resp.data有一个latlng地址列表,我可以在进入该页面时加载地图.
但是当我回到最后一页并选择另一个地址时,它无法加载我可以console.log使用的地图latlng.