Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Use <a href="http://developer.android.com/reference/android/location/Location.html#distanceTo%28android.location.Location%29" rel="nofollow noreferrer">Location.distanceTo()</a> to get a list of distances from the current location and all the locations in the database. </p> <p>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</p> <blockquote> <p>Because what i wish to do is that 5best nearest location which i get from distance.To()</p> </blockquote> <p>Once you get these locations, You can send it in a String of the format </p> <p>String topFive = "lat1,lon1 lat2,lon2 lat3,lon3 ..." </p> <pre><code>Intent intent = new Intent(getBaseContext(), YourListActivity.class); intent.putExtra("TOP_FIVE_LOCATIONS", topFive ); startActivity(intent) </code></pre> <p>In the <code>onCreate()</code> of <code>YourListActivity.java</code></p> <pre><code>String topFive = getIntent().getStringExtra("TOP_FIVE_LOCATIONS"); </code></pre> <p>Now split this string using <code>String.split(" ")</code> and you will have an String [] of locations. Split again with "," and parse the lat, lon using <code>Double.parseDouble()</code></p> <p>You need to learn about <code>ListView</code>s next, I'll <a href="http://developer.android.com/resources/tutorials/views/hello-listview.html" rel="nofollow noreferrer">direct you to a tutorial for this.</a> </p> <p>Once you have created your <code>ListView</code>, to set the lat, lon data in an adapter, the <code>ListView</code> will render the data in this adapter. </p> <blockquote> <p>method that will be displayed in well formed in list and if you click on the list</p> </blockquote> <p>Use the <code>setOnItemClickListener()</code> to get item click events You launch the next activity with the String coordinates, like before. This is a MapView. </p> <blockquote> <p>then it will display the map of that selected item and distance from your current location to that selected plus the path.</p> </blockquote> <p>See <a href="https://stackoverflow.com/questions/2176397/drawing-a-line-path-on-google-maps">this to learn how to draw a line</a> on the MapView. </p> <p>Take baby steps since you are quite new to this. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload