List of usage examples for android.location Geocoder Geocoder
public Geocoder(Context context)
From source file:com.mhennessy.mapfly.MainActivity.java
private void initMap() { mGeocoder = new Geocoder(this); SupportMapFragment mapFragment = ((SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.map)); mMap = mapFragment.getMap();/* w w w . j a v a 2 s . c om*/ mMap.addMarker(new MarkerOptions().position(new LatLng(33.748832, -84.38751300000001)).title("Marker")); mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL); CameraPosition position = new CameraPosition.Builder().zoom(DEFAULT_ZOOM) .target(new LatLng(33.748832, -84.38751300000001)).bearing(90).tilt(DEFAULT_TILT).build(); animateCameraToPosition(position, new CancelableCallback() { @Override public void onFinish() { initUpdateTimer(); } @Override public void onCancel() { } }); }
From source file:net.frakbot.FWeather.util.WeatherHelper.java
/** * Gets the city name (where available), suffixed with the * country code./*from w w w . j a va 2 s . c o m*/ * * @param context The current {@link Context}. * @param location The Location to get the name for. * * @return Returns the city name and country (eg. "London,UK") * if available, null otherwise */ public static String getCityName(Context context, Location location) { String cityName = null; if (Geocoder.isPresent()) { Geocoder geocoder = new Geocoder(context); List<Address> addresses = null; try { addresses = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 1); } catch (IOException ignored) { } if (addresses != null && !addresses.isEmpty()) { final Address address = addresses.get(0); final String city = address.getLocality(); if (!TextUtils.isEmpty(city)) { // We only set the city name if we actually have it // (to avoid the country code avoiding returning null) cityName = city + "," + address.getCountryCode(); } } } String encodedCityName = null; try { encodedCityName = URLEncoder.encode(cityName, "UTF-8"); } catch (UnsupportedEncodingException e) { FLog.d(context, TAG, "Could not encode city name, assume no city available."); } catch (NullPointerException enp) { FLog.d(context, TAG, "Could not encode city name, assume no city available."); } return encodedCityName; }
From source file:com.quantcast.measurement.service.QCLocation.java
void setupLocManager(Context appContext) { if (appContext == null) return;/*from w ww . j a va 2s . co m*/ _locManager = (LocationManager) appContext.getSystemService(Context.LOCATION_SERVICE); if (_locManager != null) { //specifically set our Criteria. All we need is a general location Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_COARSE); criteria.setAltitudeRequired(false); criteria.setBearingRequired(false); criteria.setCostAllowed(false); criteria.setPowerRequirement(Criteria.NO_REQUIREMENT); criteria.setSpeedRequired(false); _myProvider = _locManager.getBestProvider(criteria, true); _geocoder = new Geocoder(appContext); } QCLog.i(TAG, "Setting location provider " + _myProvider); }
From source file:com.googlecode.sl4a.facade.LocationFacade.java
public LocationFacade(AndroidLibraryManager manager) { mContext = manager.getContext();/*from w w w . j a v a 2 s . co m*/ mEventFacade = manager.getReceiver(AndroidEvent.class); mManager = manager; mGeocoder = new Geocoder(mContext); mLocationManager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE); mLocationUpdates = new HashMap<>(); }
From source file:com.hoccer.api.android.LinccLocationManager.java
public Address getAddress(Location location) throws IOException { if (location == null) { return new Address(null); }/*from w w w . ja va2s. c o m*/ Geocoder gc = new Geocoder(mContext); Address address = null; List<Address> addresses = gc.getFromLocation(location.getLatitude(), location.getLongitude(), 1); if (addresses.size() > 0) { address = addresses.get(0); } return address; }
From source file:com.kinvey.samples.citywatch.CityWatch.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Logger.getLogger(HttpTransport.class.getName()).setLevel(LOGGING_LEVEL); kinveyClient = ((CityWatchApplication) getApplication()).getClient(); if (!kinveyClient.user().isUserLoggedIn()) { login();//from w ww. ja v a 2s . c o m } else { getSupportActionBar().setDisplayHomeAsUpEnabled(true); // Note there is no call to SetContentView(...) here. // Check out onTabSelected()-- the selected tab and associated // fragment // is // given // android.R.id.content as it's parent view, which *is* the content // view. Basically, this approach gives the fragments under the tabs // the // complete window available to our activity without any unnecessary // layout inflation. setUpTabs(); curEntity = new CityWatchEntity(); nearbyAddress = new ArrayList<Address>(); nearbyEntities = new ArrayList<CityWatchEntity>(); locationmanager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); locationmanager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 5000, 100, this); if (Geocoder.isPresent()) { geocoder = new Geocoder(this); } // get last known location for a quick, rough start. Try GPS, if // that // fails, try network. If that fails wait for fresh data lastKnown = locationmanager.getLastKnownLocation(LocationManager.GPS_PROVIDER); if (lastKnown == null) { lastKnown = locationmanager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); } if (lastKnown == null) { // if the device has never known it's location, start at 0...? lastKnown = new Location(TAG); lastKnown.setLatitude(0.0); lastKnown.setLongitude(0.0); } Log.i(TAG, "lastKnown -> " + lastKnown.getLatitude() + ", " + lastKnown.getLongitude()); setLocationInEntity(lastKnown); } }
From source file:com.ratebeer.android.gui.fragments.PlacesFragment.java
@Override public void onStartLocationSearch(String query) { // Try to find a location for the user query, using a Geocoder try {//from w w w. j av a 2s .c o m List<Address> point = new Geocoder(getActivity()).getFromLocationName(query, 1); if (point.size() <= 0) { // Cannot find address: give an error publishException(null, getString(R.string.error_nolocation)); } else { // Found a location! Now look for places lastLocation = new Location(GEOCODER_PROVIDER); lastLocation.setLongitude(point.get(0).getLongitude()); lastLocation.setLatitude(point.get(0).getLatitude()); execute(new GetPlacesAroundCommand(getUser(), DEFAULT_RADIUS, lastLocation.getLatitude(), lastLocation.getLongitude())); } } catch (IOException e) { // Can't connect to Geocoder server: give an error publishException(null, getString(R.string.error_nolocation)); } }
From source file:it.ms.theing.loquitur.functions.LocationInterface.java
/** * Get a string with the location.// w w w . ja v a 2 s . c o m * @param lat * latitude * @param lon * longitude * @return * location or empty string */ @JavascriptInterface public String geoCoder(float lat, float lon) { try { Geocoder geo = new Geocoder(context); if (!geo.isPresent()) return ""; List<Address> addresses = geo.getFromLocation(lat, lon, 1); if (addresses == null) return ""; if (addresses.size() > 0) { JSONArray ja = new JSONArray(); if (addresses.get(0).getFeatureName() != null) ja.put(addresses.get(0).getFeatureName()); else ja.put(""); if (addresses.get(0).getAddressLine(0) != null) ja.put(addresses.get(0).getAddressLine(0)); else ja.put(""); if (addresses.get(0).getLocality() != null) ja.put(addresses.get(0).getLocality()); else ja.put(""); if (addresses.get(0).getAdminArea() != null) ja.put(addresses.get(0).getAdminArea()); else ja.put(""); if (addresses.get(0).getCountryName() != null) ja.put(addresses.get(0).getCountryName()); else ja.put(""); return ja.toString(); } } catch (Exception e) { } return ""; }
From source file:kien.activities.DistrictAcitivity.java
public LatLng getLocationFromAdress(String strAddress) { Geocoder geocoder = new Geocoder(this); List<Address> addresses; LatLng lng = new LatLng(0, 0); Log.e("LATLONG", "hello"); try {/*from ww w. ja v a2s . com*/ addresses = geocoder.getFromLocationName(strAddress, 5); Log.e("LATLONG", strAddress + ""); if (addresses == null) { return null; } Address location = addresses.get(0); location.getLatitude(); location.getLongitude(); Log.e("LATLONG", location.getLatitude() + " " + location.getLongitude()); lng = new LatLng(location.getLatitude(), location.getLongitude()); } catch (IOException e) { Log.e("LATLONG", strAddress + " error"); e.printStackTrace(); } return lng; }
From source file:org.croudtrip.fragments.join.JoinSearchFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); geocoder = new Geocoder(getActivity()); dbHelper = ((MainApplication) getActivity().getApplication()).getHelper(); }