gpt4 book ai didi

angularjs - 如何在 ionic 谷歌地图中长按/按住时获取坐标值

转载 作者:行者123 更新时间:2023-12-02 01:22:57 30 4
gpt4 key购买 nike

我正在尝试在从 Google map 点击或按住 ionic 事件时获取坐标。

按住时,我在浏览器控制台中获取值,但未获取设备中的值。

如何解决这个问题?我需要在使用 ionic 框架 [谷歌地图] 的移动应用程序中按住/点击时获取值。

如有任何帮助,我们将不胜感激。在此先致谢。

.controller('HomeCtrl', function ($scope, $rootScope, $cordovaGeolocation, $ionicLoading, $ionicGesture) {

$ionicLoading.show({
template: '<ion-spinner icon="bubbles"></ion-spinner><br/>Acquiring location!'
});

var posOptions = {
enableHighAccuracy: true,
timeout: 20000,
maximumAge: 0
};
$cordovaGeolocation.getCurrentPosition(posOptions).then(function (position) {
var lat = position.coords.latitude;
var long = position.coords.longitude;
$rootScope.currentlat = lat;
$rootScope.currentlong = long;
var myLatlng = new google.maps.LatLng(lat, long);
$rootScope.myLatlng = myLatlng;
var mapOptions = {
center: myLatlng,
zoom: 10,
mapTypeId: google.maps.MapTypeId.ROADMAP
};

var map = new google.maps.Map(document.getElementById("map"), mapOptions);

$scope.map = map;
marker = new google.maps.Marker({
position: myLatlng,
map: $scope.map
});

var element = angular.element(document.querySelector('#map'));
$ionicGesture.on('hold', function(e){
$scope.$apply(function() {
alert('hold happens');
google.maps.event.clearListeners(map, 'click');
google.maps.event.addListener(map, 'click', function(event) {
alert(event.latLng);
});
});
}, element);

google.maps.event.addListener(marker, "click", function (event) {
});

$ionicLoading.hide();
}, function (err) {
$ionicLoading.hide();
console.log(err);
});

}

最佳答案

我认为你的问题是你的使用

$ionicGesture.on('保持')

Iconic 使用 Cordova,而 Cordova 谷歌地图有自己的事件处理程序,因为“ map ”在 native View 中,与 JavaScript 无关。您可以阅读更多详细信息 here .

所以一旦您的设备准备就绪

  var map       = new google.maps.Map(document.getElementById("map"), mapOptions),
longClick = plugin.google.maps.event.MAP_LONG_CLICK;

map.on(longClick, function (latLng) {

var selectedLatLocation = latLng.lat.toString();
var selectedLongLocation = latLng.lng.toString();

alert(selectedLatLocation, selectedLongLocation);


});

关于angularjs - 如何在 ionic 谷歌地图中长按/按住时获取坐标值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38847998/

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