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. :)
With the help of latitude and longitude, you can get city name and address. To get full street name, use getMaxAddressLineIndex(). In onLocationChanged, check whether you are getting current location or not. @T.
There are two ways to get the current location of any Android device: Android's Location Manager API. Fused Location Provider: Google Play Services Location APIs.
First, create a Location Manager object by calling the getSystemService() method and LOCATION_SERVICE as an argument. Call getBestProvider() to get the location in the form of a string. Now the provider to getLastKnownLocation() as an argument to get the location.
Steps to get current latitude and longitude in Android Location permissions for the manifest file for receiving the location update. Create a LocationManager instance as a reference to the location service. Request location from LocationManager. Receive location update from LocationListener on change of location.
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With