Reputation: 4037
I want to implement a feature in my app where I can see my current location and I should even have an option to set it manually, if the location is not accurate. How can this be done? Should I use a webservice or something?
Revised
Guess i was not very clear in my question. Sorry about it. I am currently able to get my lat and long. But there are times when its not very accurate. In that scenario i should be able to enter my place name (state) and i want to receive the standard lat long for that place.. i just wanted to know how to implement it ..
Upvotes: 2
Views: 5843
Reputation: 467
Youll need a geocoder, an api that converts a street, city name to lat. and lng. values.
If you have already a way to make http requests and parse json you could use the google web api: https://developers.google.com/maps/documentation/geocoding/intro?hl=de , it returns good results and is kind of accurate. Furthermore it has more info than just lat and lng.
And all in one soultion would be the google geocoder Object that is backward compatible until api level 1: https://developer.android.com/reference/android/location/Geocoder.html . This one tends to not always return good results, especially for smaller villages and not so good known places.
Ask if you need more help etc..
Julius
Upvotes: 0
Reputation: 39023
You probably need Reverse Geocoding ( http://en.wikipedia.org/wiki/Reverse_geocoding ). There are some free services for this. Search for "Reverse Geocoding" and you will find some free options. I've never used them, so I can't recommend any.
Upvotes: 0
Reputation: 40218
Here's a little MockLocationProvider
class I've written for my purposes. It just changes latitude and longitude of a location object and returns it.
public class MockLocationProvider {
public static Location getMockLocation(double latitude, double longitude) {
Location location = new Location(LocationManager.GPS_PROVIDER);
location.setLatitude(latitude);
location.setLongitude(longitude);
return location;
}
}
However, can't really understand why you'd want to use it in a real application. I'm using this just for testing. Anyway, hope this helps.
Upvotes: 3