Pregunta

I am making location aware application. I have XML file on server containing information of different stores with latitude and longitude coordinates. Now in my application i can get my current latitude and longitude coordinates and can parse XML file as well.

But how can i figure out nearest store according to my current coordinates from XML file?

If we use google Api it returns you xml file containing nearest locations according to query. but here in my case i am using xml file on server.

Please suggest

¿Fue útil?

Solución

I think you'd be better off converting your data into a DB format (sqlite/mysql) so that the user can submit their lat/Lng point and just get the correct item returned...otherwise you'd need to parse and compare the whole file each time...but, you can still use that formula (it's really just shifting the comparison step to the DB query rather than within your app)

Edit: this has an example of a SQL query that implements haversine and returns x results: MySQL Great Circle Distance (Haversine formula)

Otros consejos

This is the haversine formula for calculating distance between two points on the earth:

a = sin²(Δlat/2) + cos(lat1)*cos(lat2)*sin²(Δlong/2);
c = 2*atan2(√a, √(1−a));
d = R*c;

You can easily adapt it in obj-c.

Please note: R is radius of the earth = 6,371km;

So just calculate the latitude and the longitude difference of both points and calculate d based on it.

Hope this helps.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top