Advertisement
Guest User

Geocoder services are not available

a guest
Jan 21st, 2015
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. Getting: Unable to geocode zipcode (Geocoder services are not available)
  2.  
  3. using this link, provided by YOU: http://stackoverflow.com/questions/3641304/get-latitude-and-longitude-using-zipcode
  4.  
  5. PERMISSION DEFINED IN MANIFEST:
  6.  
  7. <uses-permission android:name="android.permission.INTERNET"/>
  8. <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
  9. <uses-permission android:name="android.permission.ACCESS_GPS" />
  10.  
  11. btnSearchByPostalCode.setOnClickListener(new OnClickListener() {
  12.  
  13. @Override
  14. public void onClick(View v) {
  15. // TODO Auto-generated method stub
  16. // strPostalCode = editPostalCode.getText().toString();
  17. strPostalCode = "90012";
  18.  
  19. try {
  20. geocoder = new Geocoder(getBaseContext(), Locale.getDefault());
  21. List<Address> addresses = geocoder.getFromLocationName(strPostalCode, 1);
  22. if (addresses != null && !addresses.isEmpty()) {
  23. Address address = addresses.get(0);
  24. // Use the address as needed
  25. String message = String.format("Latitude: %f, Longitude: %f",
  26. address.getLatitude(), address.getLongitude());
  27. Toast.makeText(LocationsActivity.this, message, Toast.LENGTH_LONG).show();
  28. } else {
  29. // Display appropriate message when Geocoder services are not available
  30. Toast.makeText(LocationsActivity.this, "Unable to geocode zipcode", Toast.LENGTH_LONG).show();
  31. }
  32. } catch (IOException e) {
  33. // handle exception
  34. }
  35. }
  36. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement