Reputation: 1203
I do not need to display a map. However, I need to use the gps/3g network to locate my current positions ADDRESS (not long and lat) this will then be added to a automated sms response to inform a person that I currently cant reply, & the include the string address of my current location. I have the sms stuff working, just need to figure out a method of accessing the gps and pulling an address. I have seen sample code for lat/long. Perhaps I need to convert lat/long into an address within the google maps API? I am unsure howto go about it. Any advice/code snippets/similar tutorials welcome! Thanks. :)
Upvotes: 19
Views: 49753
Reputation: 3134
As you know for getting location address you can use google GeoCoder
beside that for get location addresses by providing latitude and longitude you can use this API.this is reliable and more faster than google Geocoder.Here i attach the link and small example...
API url -
you can concatenate latitude and longitude value next to equal sign at the url.
example -
lat = 6.123456
lng = 79.123456
String url =
"https://maps.googleapis.com/maps/api/geocode/json?latlng=lat+","+lng";
this will return a nice jsonObject and you can play with it, just try this.Currently im using this API for my location services and its more faster than normal google geoCoder API.To catch the json response you can use volley or anything.Happy coding.
Upvotes: 0
Reputation: 57672
The answer is here: http://developer.android.com/reference/android/location/Geocoder.html
You need to create Geocoder object and call getFromLocation(double latitude, double longitude, int maxResults)
Geocoder gCoder = new Geocoder(myContext);
ArrayList<Address> addresses = gCoder.getFromLocation(123456789, 123456789, 1);
if (addresses != null && addresses.size() > 0) {
Toast.makeText(myContext, "country: " + addresses.get(0).getCountryName(), Toast.LENGTH_LONG).show();
}
Upvotes: 15
Reputation: 28509
There are two steps to this:
Get the current location - latitude & longitude, using the GPS, network, last-known location etc. The Android location documentation includes sample code.
Use the Android Geocoder class to request a lookup to convert the lat/long to an Address (from which you can easily extract city, country, street, etc). Specifically, you need to use the getFromLocation() method
Note:
Upvotes: 28