2

I am using cordova in building the google map for device platform.

What I am going to ask is that, how to check if the user position is change?

Because the scenario is, when user is away from the specified place, the page will be redirected to logout page.

Here is the working map I have for static map (with no position change yet)

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'
      });

So the function to achieve what I want is more or less like this:

var positionMust = x, -y; 

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

We need to check this everytime user is moving away.

Can anybody help? Many many thanks in advance.

Al Kasih
  • 887
  • 5
  • 24

1 Answers1

3

You can use navigator.geolocation API as exemplified in this post:

Accessing a Google Maps API on pageload with Angular

In particular are of your interest navigator.geolocation.getCurrentPosition() and navigator.geolocation.watchPosition().

and it's also possible to check if a position is within a certain region using Google Geometry Library, see:

Determine if location is within a certain region in Google Map

All the geolocation APIs above mentioned are implemented on devices by the cordova-plugin-geolocation.

Community
  • 1
  • 1
beaver
  • 17,333
  • 2
  • 40
  • 66