Arun Abraham
Arun Abraham

Reputation: 4037

How to get/set current location programmatically?

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

Answers (3)

juliusmh
juliusmh

Reputation: 467

Youll need a geocoder, an api that converts a street, city name to lat. and lng. values.

Ask if you need more help etc..
Julius

Upvotes: 0

zmbq
zmbq

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

Egor
Egor

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

Related Questions