问题
I am making store locator application. In my application i am showing nearest store to given latitude and longitude. i am getting my current lan. and lot.
I have xml file on server containing all information of stores and latitude and longitude. What i am thinking to connect application with that xml file and gets nearest stores according to given coordinates. Now problem is how can i get nearest stores to given coordinates.
I have heared about haversine formula but how can i use that formula to get nearest stores from xml file? or if there is other way please suggest
回答1:
If i were you i would parse all the file to get the list of stores. classed by X and then Y.
Then to get the list of the closest shops just take them in the list.
I'm pretty sure you won't be able to get the shops on the fly without parsing your file.
Another way is to send a request to the server wich answer you with only the closer shops! Every task made on a portable device such as an iphone cost much time and battery than if it was done on the server.
回答2:
You might want to get your geodata, zip's etc. in a database. Look for that at
opengeodb
or some similar. You have to extend your sqlite with a distanceFunc, because arcSin and arcCos are not part of the sqlite. In your app, you then simply compare your stores lat and long to those of your shop. A example of the math can be found here
http://www.mamat-online.de/umkreissuche/opengeodb.php
although it's in german. A good tutorial can be found here:
http://www.thismuchiknow.co.uk/?p=71
HTH marcus
来源:https://stackoverflow.com/questions/7092752/extracting-nearest-stores-based-on-coordinates-from-xml-file