Note that there are some explanatory texts on larger screens.

plurals
  1. POusing geocoder with myLocationOverlay
    primarykey
    data
    text
    <p>i try to get the current zip code from the longitude and latitude which MyLocationOverlay delivers and set this to a EditView on my Activity.</p> <p>The Activity crashs when i try to get the longitude and latitude from MyLocationOverlay.</p> <p>Whats wrong with this code?</p> <p>Regards, float</p> <p>LogCat output: <a href="http://codepaste.net/vs6itk" rel="nofollow">http://codepaste.net/vs6itk</a> Line 59 is the following line: </p> <pre><code> double currentLatitude = myLocationOverlay.getMyLocation().getLatitudeE6(); </code></pre> <p>Here is my Code:</p> <pre><code>protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.partner_suche); final EditText tView = (EditText) findViewById(R.id.editTextPLZ); final MapView mView = (MapView) findViewById(R.id.mapview); mView.getController().setZoom(14); List&lt;Overlay&gt; mapOverlays = mView.getOverlays(); myLocationOverlay = new MyCustomLocationOverlay(this, mView); mapOverlays.add(myLocationOverlay); myLocationOverlay.enableMyLocation(); myLocationOverlay.enableCompass(); myLocationOverlay.runOnFirstFix(new Runnable() { public void run() { mView.getController().animateTo(myLocationOverlay.getMyLocation()); } }); Geocoder gc = new Geocoder(this, Locale.getDefault()); double currentLatitude = myLocationOverlay.getMyLocation().getLatitudeE6(); double currentLongitute = myLocationOverlay.getMyLocation().getLongitudeE6(); try { List&lt;Address&gt; addresses = gc.getFromLocation(currentLatitude, currentLongitute, 1); if (addresses.size() &gt; 0) { tView.setText(addresses.get(0).getLocality()); } } catch (IOException e) { } } </code></pre> <p>EDIT: I created a LocationListener to get my current location. Now the part crashes where i try to run gc.getFromLocation(latitude, longitude, 1); I can't read the Exception? :/</p> <pre><code>LocationManager locationManager; String context = Context.LOCATION_SERVICE; locationManager = (LocationManager)getSystemService(context); String provider = LocationManager.GPS_PROVIDER; LocationListener locationListener = new LocationListener() { public void onLocationChanged(Location location) { updateWithNewLocation(location); } public void onProviderDisabled(String provider){ updateWithNewLocation(null); } public void onProviderEnabled(String provider){ } public void onStatusChanged(String provider, int status,Bundle extras){ } }; locationManager.requestLocationUpdates(provider, 0, 0, locationListener); private void updateWithNewLocation(Location location) { final EditText tView = (EditText) findViewById(R.id.editTextPLZ); double latitude = location.getLatitude(); double longitude = location.getLongitude(); Geocoder gc = new Geocoder(this, Locale.getDefault()); if (location != null) { try { List&lt;Address&gt; addresses = gc.getFromLocation(latitude, longitude, 1); if (addresses.size() &gt; 0) { Address address = addresses.get(0); for (int i = 0; i &lt; address.getMaxAddressLineIndex(); i++){ tView.setText(address.getPostalCode()); } } } catch (Exception e) { } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload