Here's a function that'll return the angle between two LatLngs:
function getAngle(from, to){
function wrapAngle(angle){
if (angle>=360) {
angle-=360;
} else if (angle<0){
angle+=360;
}
return angle;
}
var DEGREE_PER_RADIAN=57.2957795, RADIAN_PER_DEGREE=0.017453;
var dLat=to.lat()-from.lat(), dLng=to.lng()-from.lng();
var yaw=Math.atan2(dLng*Math.cos(to.lat()*RADIAN_PER_DEGREE),
dLat)*DEGREE_PER_RADIAN;
return wrapAngle(yaw);
}
If you monitor the angle from the device to the destination on each
device position update, comparing the latest angle to the last angle
then you'll have an idea whether the device is maintaining it's course
or not.
Martin.
On Nov 18, 5:02 pm, Whops <[email protected]> wrote:
> Hello.
>
> I'm drawing a direction by using Geocoder and DirectionsService. And I
> want to know is a coordinate in my direction?
>
> My system works like this :
>
> 1- Get GPS data from GPS device.
> 2- Save the data to local server.
> 3- Show device position every second on google map on local server.
>
> if device not going on right way I want to show an alert or anythink
> else.
> Is this possible?
> Or can I find the distance between device position and the nearest
> point of the direction?
>
> Thanks for all helps.
--
You received this message because you are subscribed to the Google Groups
"Google Maps JavaScript API v3" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-maps-js-api-v3?hl=en.