0
votes

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);
                }
            }
1

1 Answers

1
votes

There were bugs reported in this line of code geocoder.getFromLocation(position.latitude,position.longitude,0);

it has nothing to do with your code, i've had it happen to me too. On some devices it works, and on some doesnt, and sometimes it works and sometimes it doesnt on the device that it does work on.

if you notice there would be a yellow line in your logcat stating that it failed to connect to some service...