获取用户在Ionic物理设备中的当前位置(iOS版本)

时间:2018-07-21 11:46:10

标签: javascript html5 ionic-framework geolocation

我正在尝试获取设备在Ionic中的位置。 早些时候,我试图通过https://ionicframework.com/docs/native/geolocation/

但是,它不断给我“仅允许安全来源”错误。

因此,我将地理位置代码移到了https://location-for-houseq.herokuapp.com上的Heroku应用中

这个想法是在Ionic的应用浏览器中打开链接,然后将位置存储在localStorage中,并通过Typescript代码进行访问。但这是行不通的。

地理位置代码是

$(window).ready(function(){
console.log("Window ready")
function getLocation(){
    console.log('Getting location');
    if (navigator.geolocation) {
      navigator.geolocation.getCurrentPosition(function(position) {
        var pos = {
          lat: position.coords.latitude,
          lng: position.coords.longitude
        };

        $('#output').html(JSON.stringify(pos));
      }, function() {
        // handleLocationError(true, infoWindow, map.getCenter());
      },{enableHighAccuracy: true,maximumAge: 10000});
    } else {
      // Browser doesn't support Geolocation
      console.error('Browser doesn\'t support Geolocation');
    }
}
$(document).on('click','#trigger',function(){
    console.log('clicked');
    getLocation();
});

});

如果有人知道我在做什么错,或者有任何基于Ionic的解决方法,我很乐意尝试一下。

0 个答案:

没有答案