Anyone know how to do a Find My Car type of app?

Hello,

I need to use the gps on my phone to have an arrow point the direction do a set of gps coordinates I have just like they do for a Find My Car type of app. I am not doing that app but using the same methods for another app.

I need to point an arrow in the direction and also calculate the distance in feet or yards to that destination.

Does anyone know where I can find some code example for this? I know there is a compass example with Corona. But I want to point to a set of coordinates, not the degrees.

Thanks,

Warren

I found this website that gives the bearing which is what I need. Now I just need to figure out how to do this in Corona with lua. Has anyone else done this?

http://www.movable-type.co.uk/scripts/latlong.html

Try these two functions:

local function angleBetween( srcX, srcY, dstX, dstY )
    local angle = ( math_deg( math_atan2( dstY-srcY, dstX-srcX ) )+90 )
    return angle%360
end

local function distBetween( point1, point2 )
    local xFactor = point2.x-point1.x ; local yFactor = point2.y-point1.y
    local dist = math_sqrt((xFactor*xFactor) + (yFactor*yFactor))
    return dist
end
 

Its really all about right angle math.  This is a great site:  http://www.mathwarehouse.com/geometry/triangles/right-triangle.php

While on a planetary scale, you have to factor some curve into the distance, in most uses (within a few miles of two points), the world is flat enough that right angle math is accurate enough.

Rob

Thanks! I am calculating the distance and bearing only within 3 miles at the most. And as I move closer to the destination it is updating the bearing so any errors will be narrowed down as I get closer. I am trying this now and will let you know as well as anyone else how it works.

Warren

Given that GPS coordinates are inherently inaccurate anyway (for security purposes), Any curvature errors are going to be insignificant.

Rob

The bearing part works great. How do I use the distance with lat/lon for each point?

In the distance function it takes two x, y points.  You have two x, y points, with latitude being the .y and longitude being the .x.

Rob

You can also use the Haversine Formula to get the approximate distance between two GPS points.

I provided the code in this forum post: http://forums.coronalabs.com/topic/53446-distance-find-in-location/?hl=haversine#entry277901

I have some bearing code that works with long/lat here http://simon.fearby.com/blog/?p=2117

Nice post!

Rob

I found this website that gives the bearing which is what I need. Now I just need to figure out how to do this in Corona with lua. Has anyone else done this?

http://www.movable-type.co.uk/scripts/latlong.html

Try these two functions:

local function angleBetween( srcX, srcY, dstX, dstY )
    local angle = ( math_deg( math_atan2( dstY-srcY, dstX-srcX ) )+90 )
    return angle%360
end

local function distBetween( point1, point2 )
    local xFactor = point2.x-point1.x ; local yFactor = point2.y-point1.y
    local dist = math_sqrt((xFactor*xFactor) + (yFactor*yFactor))
    return dist
end
 

Its really all about right angle math.  This is a great site:  http://www.mathwarehouse.com/geometry/triangles/right-triangle.php

While on a planetary scale, you have to factor some curve into the distance, in most uses (within a few miles of two points), the world is flat enough that right angle math is accurate enough.

Rob

Thanks! I am calculating the distance and bearing only within 3 miles at the most. And as I move closer to the destination it is updating the bearing so any errors will be narrowed down as I get closer. I am trying this now and will let you know as well as anyone else how it works.

Warren

Given that GPS coordinates are inherently inaccurate anyway (for security purposes), Any curvature errors are going to be insignificant.

Rob

The bearing part works great. How do I use the distance with lat/lon for each point?

In the distance function it takes two x, y points.  You have two x, y points, with latitude being the .y and longitude being the .x.

Rob

You can also use the Haversine Formula to get the approximate distance between two GPS points.

I provided the code in this forum post: http://forums.coronalabs.com/topic/53446-distance-find-in-location/?hl=haversine#entry277901

I have some bearing code that works with long/lat here http://simon.fearby.com/blog/?p=2117