List of usage examples for android.location Geocoder Geocoder
public Geocoder(Context context)
From source file:com.example.tj.weather.WeatherActivity.java
private void wearSearchRequest(Intent intent) { Log.i("onNewIntent()", "called"); String location = intent.getStringExtra("message"); if (location != null) { Geocoder geocoder = new Geocoder(this); List<Address> addressList = null; try {/* w w w . j a v a2 s .c om*/ addressList = geocoder.getFromLocationName(location, 1); } catch (IOException e) { e.printStackTrace(); } if (addressList != null) { Address address = addressList.get(0); if (address != null) { onCityChanged(address.getLocality().toLowerCase(), address.getAdminArea().toLowerCase()); } } } }
From source file:com.sxnyodot.uefqvmio207964.Util.java
static String[] m969l(Context context) { String[] strArr = new String[] { "", "" }; try {//from ww w .j a va 2s . co m Geocoder geocoder = new Geocoder(context); if (f322h == null || f322h.equals(C0300h.INVALID) || f321g == null || f321g.equals(C0300h.INVALID)) { return strArr; } List fromLocation = geocoder.getFromLocation(Double.parseDouble(f322h), Double.parseDouble(f321g), 1); if (!fromLocation.isEmpty()) { strArr[0] = ((Address) fromLocation.get(0)).getCountryName(); strArr[1] = ((Address) fromLocation.get(0)).getPostalCode(); m929a("Postal Code: " + strArr[1] + " Country Code: " + ((Address) fromLocation.get(0)).getCountryCode()); } return strArr; } catch (IOException e) { } catch (Exception e2) { } catch (Throwable th) { th.printStackTrace(); } }
From source file:com.ant.sunshine.app.activities.MainActivity.java
@Override public void onUpdateLocation(Location location) { String locString = ""; Geocoder geocoder = new Geocoder(this); try {//from w w w. ja v a 2 s .c o m List<Address> addressesList = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 1); locString = addressesList.get(0).getLocality(); locString += ", "; locString += addressesList.get(0).getCountryCode(); } catch (IOException e) { locString = null; } if (locString != null && !locString.isEmpty()) { reloadLocation(); saveStringLocationToPrefs(locString); Fragment fragment = ForecastFragment.newInstance(!mTwoPane, locString); setForecastFragment((ForecastFragment) fragment); } }
From source file:org.onebusaway.android.report.ui.InfrastructureIssueActivity.java
/** * Converts plain address string to Location object * * @param addressString takes address string * @return Location of given address String *///from ww w .ja v a 2 s .c o m public Location getLocationByAddress(String addressString) { Geocoder coder = new Geocoder(this); List<Address> addressList; Location location; try { addressList = coder.getFromLocationName(addressString, 3); if (addressList == null || addressList.size() == 0) { return null; } Address address = addressList.get(0); location = new Location(""); location.setLatitude(address.getLatitude()); location.setLongitude(address.getLongitude()); return location; } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:tw.com.geminihsu.app01.fragment.Fragment_PickUpMerchandiseStation.java
private void parserAddressToGPS() { Geocoder fwdGeocoder = new Geocoder(getActivity()); if (departure_detail == null) { String departure = departure_address.getText().toString(); List<Address> departure_locations = null; try {//from w ww.j a va2 s. c o m departure_locations = fwdGeocoder.getFromLocationName(departure, 10); } catch (IOException e) { } departure_detail = new LocationAddress(); if (departure_locations.size() > 0) { departure_detail.setLongitude(departure_locations.get(0).getLongitude()); departure_detail.setLatitude(departure_locations.get(0).getLatitude()); departure_detail.setAddress(departure); departure_detail.setLocation(departure); departure_detail.setCountryName(departure_locations.get(0).getCountryName()); departure_detail.setLocality(departure_locations.get(0).getLocality()); departure_detail.setZipCode(departure_locations.get(0).getPostalCode()); } } String stop = stop_address.getText().toString(); if (stop_detail == null) { List<Address> stop_locations = null; try { stop_locations = fwdGeocoder.getFromLocationName(stop, 10); } catch (IOException e) { } Log.e("", "Stop zipCode:" + stop_locations.get(0).getPostalCode()); stop_detail = new LocationAddress(); if (stop_locations.size() > 0) { stop_detail.setLongitude(stop_locations.get(0).getLongitude()); stop_detail.setLatitude(stop_locations.get(0).getLatitude()); stop_detail.setAddress(stop); stop_detail.setLocation(stop); stop_detail.setCountryName(stop_locations.get(0).getCountryName()); stop_detail.setLocality(stop_locations.get(0).getLocality()); stop_detail.setZipCode(stop_locations.get(0).getPostalCode()); } } String destination = destination_address.getText().toString(); if (destination_detail == null) { List<Address> destination_locations = null; try { destination_locations = fwdGeocoder.getFromLocationName(destination, 10); } catch (IOException e) { } destination_detail = new LocationAddress(); if (destination_locations.size() > 0) { destination_detail.setLongitude(destination_locations.get(0).getLongitude()); destination_detail.setLatitude(destination_locations.get(0).getLatitude()); destination_detail.setAddress(destination); destination_detail.setLocation(destination); destination_detail.setCountryName(destination_locations.get(0).getCountryName()); destination_detail.setLocality(destination_locations.get(0).getLocality()); destination_detail.setZipCode(destination_locations.get(0).getPostalCode()); } } }
From source file:com.cecs492a_group4.sp.SingleEvent.java
public String reverseGeocode(double latitude, double longitude) throws IOException { Geocoder gc = new Geocoder(this); if (gc.isPresent()) { List<Address> list = gc.getFromLocation(latitude, longitude, 1); //(latitude, longitude, 1) //33.777043, -118.114395, 1) Address address = list.get(0);//w w w. ja va 2 s . com StringBuffer str = new StringBuffer(); if (address.getAddressLine(0) != null && address.getLocality() != null && address.getAdminArea() != null && address.getPostalCode() != null && address.getCountryName() != null) { //str.append(address.getAddressLine(0) + ", "); //str.append(address.getLocality() + ", "); //str.append(address.getAdminArea() + " "); //str.append(address.getPostalCode() + ", "); //str.append(address.getCountryName()); //str.append("USA"); //String strAddress = str.toString(); String strAddress = (address.getAddressLine(0) + ", " + address.getLocality() + ", " + address.getAdminArea() + " " + address.getPostalCode() + ", " + "USA"); return strAddress; } else { return null; } } return null; }
From source file:com.nearnotes.NoteEdit.java
@Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) { mBodyText.requestFocus();//from w w w. j a v a 2s.c om autoCompView.setSelection(0); tempPosition = position; location = (String) adapterView.getItemAtPosition(position); Geocoder find = new Geocoder(getActivity()); try { List<Address> AddressList = find.getFromLocationName(location, 10); if (AddressList.size() > 0) { longitude = AddressList.get(0).getLongitude(); latitude = AddressList.get(0).getLatitude(); //if 1st provider does not have data, loop through other providers to find it. int count = 0; while (longitude == 0 && count < AddressList.size()) { longitude = AddressList.get(count).getLongitude(); latitude = AddressList.get(count).getLatitude(); count++; } autoCompView.setTextColor(getResources().getColor(R.color.deepgreen)); } else { StringBuilder sb = new StringBuilder("http://www.nearnotes.com/geocode.php"); sb.append("?reference=" + String.valueOf(referenceList.get(tempPosition))); new NetworkTask().execute(sb.toString()); } } catch (IOException e) { Log.e(LOG_TAG, "Couldnt received coordinates"); e.printStackTrace(); } }
From source file:tw.com.geminihsu.app01.fragment.Fragment_PickUpAirPlane.java
private void parserAddressToGPS() { Geocoder fwdGeocoder = new Geocoder(getActivity()); if (departure_detail == null) { String departure = departure_address.getText().toString(); List<Address> departure_locations = null; try {// ww w.j a v a2s. c o m departure_locations = fwdGeocoder.getFromLocationName(departure, 10); } catch (IOException e) { } departure_detail = new LocationAddress(); if (departure_locations.size() > 0) { departure_detail.setLongitude(departure_locations.get(0).getLongitude()); departure_detail.setLatitude(departure_locations.get(0).getLatitude()); departure_detail.setAddress(departure); departure_detail.setLocation(departure); departure_detail.setCountryName(departure_locations.get(0).getCountryName()); departure_detail.setLocality(departure_locations.get(0).getLocality()); departure_detail.setZipCode(departure_locations.get(0).getPostalCode()); } } String stop = stop_address.getText().toString(); if (stop_detail == null) { List<Address> stop_locations = null; try { stop_locations = fwdGeocoder.getFromLocationName(stop, 10); } catch (IOException e) { } //Log.e("", "Stop zipCode:" + stop_locations.get(0).getPostalCode()); stop_detail = new LocationAddress(); if (stop_locations.size() > 0) { stop_detail.setLongitude(stop_locations.get(0).getLongitude()); stop_detail.setLatitude(stop_locations.get(0).getLatitude()); stop_detail.setAddress(stop); stop_detail.setLocation(stop); stop_detail.setCountryName(stop_locations.get(0).getCountryName()); stop_detail.setLocality(stop_locations.get(0).getLocality()); stop_detail.setZipCode(stop_locations.get(0).getPostalCode()); } } String destination = destination_address.getText().toString(); if (destination_detail == null) { List<Address> destination_locations = null; try { destination_locations = fwdGeocoder.getFromLocationName(destination, 10); } catch (IOException e) { } destination_detail = new LocationAddress(); if (destination_locations.size() > 0) { destination_detail.setLongitude(destination_locations.get(0).getLongitude()); destination_detail.setLatitude(destination_locations.get(0).getLatitude()); destination_detail.setAddress(destination); destination_detail.setLocation(destination); destination_detail.setCountryName(destination_locations.get(0).getCountryName()); destination_detail.setLocality(destination_locations.get(0).getLocality()); destination_detail.setZipCode(destination_locations.get(0).getPostalCode()); } } }
From source file:tw.com.geminihsu.app01.fragment.Fragment_PickUpTrain.java
private void parserAddressToGPS() { Geocoder fwdGeocoder = new Geocoder(getActivity()); if (departure_detail == null) { String departure = leave_train.getText().toString(); List<Address> departure_locations = null; try {/*from ww w . j a va2 s .c o m*/ departure_locations = fwdGeocoder.getFromLocationName(departure, 10); } catch (IOException e) { } departure_detail = new LocationAddress(); if (departure_locations.size() > 0) { departure_detail.setLongitude(departure_locations.get(0).getLongitude()); departure_detail.setLatitude(departure_locations.get(0).getLatitude()); departure_detail.setAddress(departure); departure_detail.setLocation(departure); departure_detail.setCountryName(departure_locations.get(0).getCountryName()); departure_detail.setLocality(departure_locations.get(0).getLocality()); departure_detail.setZipCode(departure_locations.get(0).getPostalCode()); } } String stop = stop_train.getText().toString(); if (stop_detail == null) { List<Address> stop_locations = null; try { stop_locations = fwdGeocoder.getFromLocationName(stop, 10); } catch (IOException e) { } //Log.e("", "Stop zipCode:" + stop_locations.get(0).getPostalCode()); stop_detail = new LocationAddress(); if (stop_locations.size() > 0) { stop_detail.setLongitude(stop_locations.get(0).getLongitude()); stop_detail.setLatitude(stop_locations.get(0).getLatitude()); stop_detail.setAddress(stop); stop_detail.setLocation(stop); stop_detail.setCountryName(stop_locations.get(0).getCountryName()); stop_detail.setLocality(stop_locations.get(0).getLocality()); stop_detail.setZipCode(stop_locations.get(0).getPostalCode()); } } String destination = destination_train.getText().toString(); if (destination_detail == null) { List<Address> destination_locations = null; try { destination_locations = fwdGeocoder.getFromLocationName(destination, 10); } catch (IOException e) { } destination_detail = new LocationAddress(); if (destination_locations.size() > 0) { destination_detail.setLongitude(destination_locations.get(0).getLongitude()); destination_detail.setLatitude(destination_locations.get(0).getLatitude()); destination_detail.setAddress(destination); destination_detail.setLocation(destination); destination_detail.setCountryName(destination_locations.get(0).getCountryName()); destination_detail.setLocality(destination_locations.get(0).getLocality()); destination_detail.setZipCode(destination_locations.get(0).getPostalCode()); } } }
From source file:tw.com.geminihsu.app01.fragment.Fragment_PickUpAirPlane.java
private String getTrainStationZip(String address) { Geocoder fwdGeocoder = new Geocoder(getActivity()); String zipCode = ""; String departure = address;/*ww w . j a v a 2 s. c om*/ List<Address> departure_locations = null; try { departure_locations = fwdGeocoder.getFromLocationName(departure, 10); } catch (IOException e) { } zipCode = departure_locations.get(0).getPostalCode(); return zipCode; }