返回从字符串位置获取的默认标记的纬度和经度



我的问题是如何取现有标记的纬度和经度?让我解释一下:当我在浏览器上输入页面时,我使用以下地址显示标记位置:

<ng-map ng-if="null != evaluation" default-style="false" zoom="16" center="{{ '{{ getAddress() }}' }}" style="width: 100%; height: 430px;">
<marker centered="true" position="{{ '{{ getMarkerPosition() }}' }}" draggable="true" on-dragend="onMarkerDragEnd($event)"></marker>
</ng-map>

角部分:

$scope.getMarkerPosition = function () {
if (!$scope.address.mapPinLocationLatitude || !$scope.address.mapPinLocationLongitude) {
return $scope.getAddress();
}
return [$scope.address.mapPinLocationLatitude, $scope.address.mapPinLocationLongitude]
};

$scope.getAddress = function () {
//building the adress by getting the objects that are used for creating an address object
return streetString + ', ' + address; //streetString will be a string that has the complete address
};
$scope.onMarkerDragEnd = function ($event) {
$scope.address.mapPinLocationLatitude = $event.latLng.lat();
$scope.address.mapPinLocationLongitude = $event.latLng.lng();
uptadeRegions();
};

如果我移动标记,纬度和日志存在,方法getMarkerPosition返回一个数组,其中有2个。但是如果我不在地图上移动标记,如何获得经纬度和经度?默认值为 0,我不知道如何解决它。谢谢

编辑:

app.controller('MapController',
['$scope', 'NgMap','$state', 'SelectOptionsService', '$rootScope', '$q','GeoCoder',
function ($scope, NgMap, $state, SelectOptionsService, $rootScope, $q, GeoCoder) {

所以你使用一个地址作为标记位置,你想在初始化期间获得纬度和液化天然气? 您可以使用GeoCoder服务(由ngMap提供(

像这样:

app.controller('MapController',
['$scope', 'NgMap','$state', 'SelectOptionsService', '$rootScope', '$q','GeoCoder',
function ($scope, NgMap, $state, SelectOptionsService, $rootScope, $q, GeoCoder) {
//hired by marker:geo-callback
$scope.geoCallback = function() {
GeoCoder.geocode({
address: $scope.getAddress()
}).then(function(result) {
//explore this, you may got the position in: result[0].geometry.location
console.log('A place object is: ', result);
});
};
...
//your getAddress function
$scope.getAddress = function() {
};
}]);

在 HTML 中,在标记中您可以使用geo-callback属性

<marker ... geo-callback="geoCallback()"></marker>

在此处阅读有关地理回调的信息

最新更新