Here's the math I used in VFP using the lat/long of both endpoints to
determine the distance:
FUNCTION CalcDistance(StartingLat as Number, StartingLong as Number,
EndingLat as Number, EndingLong as Number) as Number
RETURN 3956 * 2 * ASIN(SQRT((SIN((StartingLat - EndingLat) * pi()/180
/ 2)**2) + COS(StartingLat * pi()/180) * COS(EndingLat * pi()/180) *
(SIN((StartingLong - EndingLong) * pi()/180 / 2)**2) ))
ENDFUNC && CalcDistance(StartingLat as Number, StartingLong as Number,
EndingLat as Number, EndingLong as Number) as Number
It's called from this code:
select distinct destination ;
from (;
select distinct f1.ccity as city_in, f1.cstatecode as state_in,
f1.czipcode as zip_in, ALLTRIM(f2.ccity) + ', ' + ALLTRIM(f2.cstatecode)
as destination, ;
f2.czipcode as zip_dest, this.CalcDistance(VAL(f1.clatitude),
VAL(f1.clongitude), VAL(f2.clatitude), VAL(f2.clongitude)) as Distance;
from lucounties f1, lucounties
f2;
where f1.ccity = pcCity and f1.cstatecode = pcState and
f1.ccitytype = 'D' AND f2.ccitytype = 'D' AND f1.czipcode <> f2.czipcode
;
having Distance <= piRadius;
) x1 ;
order by destination ;
INTO CURSOR (lcCursor)
fyi. Thanks for all who chimed in!
--Mike
On 2017-03-15 03:32, Alan Bourke wrote:
Yeah, as much location data as you can get (address, Zip, lat & long)
and the Google API.
--
Alan Bourke
alanpbourke (at) fastmail (dot) fm
On Wed, 15 Mar 2017, at 05:23 AM,
[email protected] wrote:
(to be done in VFP9SP2 existing app)
Customer need: to grab/query towns near a certain zip code or city
name, akin to like when you use an app where you're looking for a car
and say "show me matches within 50 miles." I'm thinking
latitude/longitude and google somehow, but I thought I'd poll the
community to see what you'd recommend.
Thanks!
--Mike
[excessive quoting removed by server]
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message:
http://leafe.com/archives/byMID/profox/[email protected]
** All postings, unless explicitly stated otherwise, are the opinions of the
author, and do not constitute legal or medical advice. This statement is added
to the messages for those lawyers who are too stupid to see the obvious.