Reputation: 35
This is my first time development in android application. This app will calculate the total distance between two address that input by the user in order to get the total distance. Is it ok to calculate the distance that assume the road is straight? by the way, this application will not show map and does not need GPS! It just needs to use geocoder to get the latitude-longitude.
Here are my questions:
android:name=".permission.MAPS_RECEIVE".
public class MainActivity extends Activity
Thanks for your reply and i would like to appreciate u guys and if possible can you please show the full AndroidManifext.xml code?
Thanks.
Upvotes: 2
Views: 4991
Reputation: 6928
You don't need to include the maps permissions.
To get the distance between 2 locations you can use the Geocoder class. This shouldn't need an y location permissions either.
The Geocoder class has a method
getFromLocationName(String locationName, int maxResults)
which returns a list of Addresses for a location input. The addresses have a latitude/longitude.
You need to convert the Address into a Location object which has methods for calculating distance between 2 locations:
distanceTo(Location dest)
Returns the approximate distance in meters between this location and the given location.
As for your second question. You should use Fragments inside of your activity. Have a read through this to understand a bit more about fragments and their advantages.
Upvotes: 1
Reputation:
Use the Geocoder to get the latitude and longitude for place 1 and place 2. Apply those values in the following method.
Location.distanceBetween(startLatitude, startLongitude, endLatitude, endLongitude, results)
Upvotes: 1