Search code examples
androidgoogle-mapsdirections

How to get road name from my location using google map not the location address


I want to get the road name in google map when I drive a car on the road using my current location, I searched more about this, but I can not find the solution. I am using the geocoder to get my location name, but it return the location address not the road that I drive a car on it. I.e, goecoder return address line as example (5- street , locality, country) When I drive on the road for 10 meters the address changed to be (6- street , locality, country) But I want only the long road name only like (street 5) I tried to user feature name ot any key in geo coder but it return the address like(5- street 5) Any one can help me please?


Solution

  • When you get your address line from the geocoder, you can make a call to get a string using getThoroughfare, this will get you a street address, such as "1600 Ampitheater Parkway", then, you can make a call to get a string using getSubThoroughfare, which if not null, may return the address part of the Thoroughfare, such as "1600" in the example posted above. Then, you can do a string replace on the Thoroughfare string replacing Sub-Thoroughfare with "" to strip out the number.