I'm reverse geocoding, using a marker. So dependant on the markers location, it will get the longitude and latitude and hence get the address from geo coder. The issue is that on some locations wheere the marker it gets an incorrect address, although the locality might be correct the remaining 'Street' etc is incorrect, also sometimes it doesnt show an address at all, the TextView remains with its previous input.
Below is my on drag listner for the marker:
public void onMarkerDragEnd(Marker marker) {
LatLng position = marker.getPosition();
Geocoder geocoder = new Geocoder(MainActivity.this);
TextView textView1 = (TextView)findViewById(R.id.textView1);
try
{
List<Address> addresses = geocoder.getFromLocation(position.latitude,position.longitude,0);
for(Address address : addresses)
{
if(address.getLocality()!=null)
{
SubStreetNumber = address.getSubThoroughfare ();
Street = address.getThoroughfare();
Area = address.getSubLocality ();
City = address.getLocality();
PostCode = address.getPostalCode();
break;
}
textView1.setText(SubStreetNumber + ", " + Street + ", " + City + ", " + PostCode);
}
}
catch(IOException ioException)
{
Log.e("MyApp","Exception",ioException);
}
}