2016-02-04 26 views
2

我正在使用科爾多瓦建設設備平臺的谷歌地圖。查看谷歌地圖中的位置變化

我現在要問的是,如何檢查用戶位置是否改變?

因爲場景是,當用戶離開指定的地方時,頁面將被重定向到註銷頁面。

這裏是工作的地圖我有靜態地圖(無位置變化還)

var longitude = position.coords.longitude; 
    var latitude = position.coords.latitude; 
    var latLong = new google.maps.LatLng(latitude, longitude); 

    var mapOptions = { 
     center: latLong, 
     zoom: 18, 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
    }; 

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

    var marker = new google.maps.Marker({ 
      position: latLong, 
      map: map, 
      title: 'my location' 
     }); 

因此函數來達到我想要的或多或少是這樣的:

var positionMust = x, -y; 

if (latLong != positionMust) 
    { 
     window.location.href//to logout 
    } 

我們需要檢查此用戶每次移走。

任何人都可以幫忙嗎?很多人提前感謝。

回答

2

您可以使用navigator.geolocation API爲這篇文章舉例:

Accessing a Google Maps API on pageload with Angular

尤其是你的興趣navigator.geolocation.getCurrentPosition()navigator.geolocation.watchPosition()的。

和它也可以檢查是否一個位置是使用Google Geometry Library在一定區域內,請參閱:

Determine if location is within a certain region in Google Map

所有地理位置的API上面提到由cordova-plugin-geolocation設備實現。