gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 21:19:01 25 4
gpt4 key购买 nike

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

  <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>

Angular 部分:

  $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();
};

如果我移动 lat 和 log 存在的标记,则 getMarkerPosition 方法返回一个包含其中 2 的数组。但是如果我不移动 map 上的标记,如何获取纬度和经度?默认是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>

了解 geo-callback here

关于javascript - 返回从字符串位置获取的默认标记的纬度和经度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45372729/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com