Exemplo n.º 1
0
 /**
  * transfer an address to coordinates
  *
  * @param strAddress the address that need to be transfered
  * @return the transfered coordinates
  */
 public static double[] toLatLong(String strAddress) {
   Geocoder geocoder = new Geocoder(ContextProvider.get(), Locale.getDefault());
   List<Address> addresses;
   double[] returnLatLong = new double[2];
   try {
     addresses = geocoder.getFromLocationName(strAddress, 1);
     if (addresses != null && addresses.size() > 0) {
       Address returnedAddress = addresses.get(0);
       returnLatLong[0] = returnedAddress.getLatitude();
       returnLatLong[1] = returnedAddress.getLongitude();
     }
   } catch (Exception e) {
     return new double[] {0.0, 0.0};
   }
   return returnLatLong;
 }
Exemplo n.º 2
0
 /**
  * transfer the coordinate to actual address
  *
  * @param latitude the latitude
  * @param longitude the longitude
  * @return the transfer address
  */
 public static String toAddress(double latitude, double longitude) {
   String myAddress;
   Geocoder geocoder = new Geocoder(ContextProvider.get(), Locale.getDefault());
   List<Address> addresses;
   try {
     addresses = geocoder.getFromLocation(latitude, longitude, 1);
     if (addresses != null && addresses.size() > 0) {
       Address returnedAddress = addresses.get(0);
       myAddress = formatAddress(returnedAddress);
     } else {
       myAddress = "";
     }
   } catch (Exception e) {
     System.out.println(e.getMessage());
     myAddress = "";
   }
   return myAddress;
 }