只是为了补充@Vikas的答案..
我可以通过更改为:
myApp.directive('geocode', ['$location', function ($location) {
return {
restrict: 'E',
scope: {
geocode: '=bind',
},
link: function($scope, uiGmapIsReady) {
var iLat, iLong;
if ($scope.geocode && $scope.geocode.latitude !== undefined) {
iLat = parseFloat($scope.geocode.latitude);
iLong = parseFloat($scope.geocode.longitude);
} else {
iLat = 19.090555;
iLong = 72.888684;
$scope.geocode = new Object;
$scope.geocode.__type = "GeoPoint";
$scope.geocode.latitude = iLat;
$scope.geocode.longitude = iLong;
}
var maps = { center: { latitude: iLat, longitude: iLong }, zoom: 12 };
$scope.map = maps;
$scope.options = {scrollwheel: false};
$scope.marker = {
id: 0,
coords: {
latitude: iLat,
longitude: iLong
},
options: { draggable: true },
events: {
dragend: function (marker, eventName, args) {
$scope.geocode.latitude = marker.getPosition().lat();
$scope.geocode.longitude = marker.getPosition().lng();
var latlng = {lat: parseFloat($scope.geocode.latitude), lng: parseFloat($scope.geocode.longitude)};
$scope.marker.options = {
draggable: true,
labelContent: $scope.address,
labelAnchor: "100 0",
labelClass: "marker-labels"
};
}
}
};
},
template:
`
<div class="row list-view">
<div class="col-lg-12">
<ui-gmap-google-map center="map.center" zoom="map.zoom" draggable="true" options="options" pan=true refresh="true">
<ui-gmap-marker coords="marker.coords" options="marker.options" events="marker.events" idkey="marker.id">
</ui-gmap-marker>
</ui-gmap-google-map>
</div>
</div>
`
};}]);
myApp.config(function (uiGmapGoogleMapApiProvider) {
uiGmapGoogleMapApiProvider.configure({
key: '',
v: '3',
libraries: 'visualization'
});});