I am developing one application in which I am having database of the places with me as a addresses in form of String. Using Geocoders I am getting the Lat/Long of the same. I also done with my current location. Now from that current location I wish to get near by 4-5 places from my database. Another thing about this is that first i wish to display the nearest 4-5 location's addresses in ListView and if you clicked on any of it then it will display the map with distance of your current location to the destination and path of it.
I got the idea of this application from already developed application famously known as "Places" in android market.
Please kindly help me out in this I am very close to my application but stuck with some small things.
Thank You Keyur
Use Location.distanceTo() to get a list of distances from the current location and all the locations in the database.
Sort the result and choose the top 5 with the least distance from the current position. Get the addresses and pass this list in an String array in extras to a new list activity
Once you get these locations, You can send it in a String of the format
String topFive = "lat1,lon1 lat2,lon2 lat3,lon3 ..."
In the
onCreate()
ofYourListActivity.java
Now split this string using
String.split(" ")
and you will have an String [] of locations. Split again with "," and parse the lat, lon usingDouble.parseDouble()
You need to learn about
ListView
s next, I'll direct you to a tutorial for this.Once you have created your
ListView
, to set the lat, lon data in an adapter, theListView
will render the data in this adapter.Use the
setOnItemClickListener()
to get item click events You launch the next activity with the String coordinates, like before. This is a MapView.See this to learn how to draw a line on the MapView.
Take baby steps since you are quite new to this.