error2013
asked on
Javascript Google Maps Geofencing Alert when current location is inside geofence area.
I have just been looking into GeoFencing and I am trying to find out how to get a javascript alert if my current location comes into the geofence.
I have been googling and cannot find any examples that actually work so I thought I'd ask here.
I need it in javascript / html5 by the way.
Can anyone help?
I have been googling and cannot find any examples that actually work so I thought I'd ask here.
I need it in javascript / html5 by the way.
Can anyone help?
What have you tried which didn't actually work? First thing to note is that Geolocation API will only work from a HTTPS site and not from a HTTP site.
ASKER
This is going to go into a phonegap/Cordova app. Do I still need https?
In that case, no. An APP can get the current position using Geolocation API without https.
You can use something like below in your javascript:
Geolocation API: Here
You can use something like below in your javascript:
navigator.geolocation.getCurrentPosition(function(position) {
do_something(position.coords.latitude, position.coords.longitude);
});
and with the coordinates you'll be able to calculate against the geofencing boundaries (e.g. check the distance between your location and the center of the geofenced area, etc.) to see if the current position lies within the GeoFence.Geolocation API: Here
ASKER
Yeah I can pull out the geolocation co-odinates but how do I add the geofence?
Well, it depends on how your system implements it. Some approaches where (x1, y1) is your target position and (x2, y2) is your current location:
- Block: check if |x2-x1| and |y2-y1| are in the allowed range separately.
- Circle (linear distance): check if ((x2-x1)^2 * (y2-y1)^2) ^ 0.5 is in the allowed range
- Path (road distance): send (x1, y1) and (x2, y2) to a mapping API (e.g. Google Maps) to retrieve the distance, and check against the allowed range.
ASKER
Check out my question here which show where I am. All is working except the geofence.
Maybe you can help fix the issue.
Thanks
Here's the link:
https://www.experts-exchan ge.com/que stions/291 41524/Cann ot-get-Geo fence-to-a ppear-in-t he-google- map.html#q uestionAdd
Maybe you can help fix the issue.
Thanks
Here's the link:
https://www.experts-exchan
note the referenced question above has been deleted
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.