List of usage examples for android.location Geocoder Geocoder
public Geocoder(Context context)
From source file:Main.java
public static double getLonByLocation(Context context, String ciudad) { Geocoder geocoder = new Geocoder(context); try {/*from ww w . ja v a 2 s.co m*/ List<Address> result = geocoder.getFromLocationName(ciudad, 1); if (result != null && result.isEmpty() == false) { return result.get(0).getLongitude(); } } catch (IOException e) { return 0D; } return 0D; }
From source file:Main.java
public static String locationToAddress(Location loc, Context context) { try {//from w ww. ja v a 2 s . c o m double latitude, longitude; String addressText = ""; geocoder = new Geocoder(context); latitude = loc.getLatitude(); longitude = loc.getLongitude(); List<Address> list = geocoder.getFromLocation(latitude, longitude, 1); if (list != null && list.size() > 0) { Address address = list.get(0); addressText = String.format("%s, %s, %s", address.getMaxAddressLineIndex() > 0 ? address.getAddressLine(0) : "", address.getLocality(), address.getCountryName()); } return addressText; } catch (IOException e) { Log.e(LogDavid, "ERROR:" + e.toString()); return ""; } }
From source file:Main.java
public static String getCountry(Context context) { @SuppressWarnings("static-access") LocationManager lm = (LocationManager) context.getSystemService(context.LOCATION_SERVICE); Location l = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); Geocoder gc = new Geocoder(context); try {// w w w .j a v a 2 s. co m List<Address> address = gc.getFromLocation(l.getLatitude(), l.getLongitude(), 1); if (address != null && address.isEmpty() == false) return address.get(0).getCountryName(); } catch (IOException e) { return ""; } return ""; }
From source file:Main.java
public static String getLocality(Context context) { @SuppressWarnings("static-access") LocationManager lm = (LocationManager) context.getSystemService(context.LOCATION_SERVICE); if (lm == null) return ""; Location l = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); if (l == null) return ""; Geocoder gc = new Geocoder(context); try {//from ww w . j a v a 2 s . c o m List<Address> address = gc.getFromLocation(l.getLatitude(), l.getLongitude(), 1); if (address != null && address.isEmpty() == false) return address.get(0).getLocality(); } catch (Exception e) { return ""; } return ""; }
From source file:no.ntnu.idi.socialhitchhiking.map.GeoHelper.java
public static void initGeocoder(Context context) { fancyGeocoder = new Geocoder(context); }
From source file:com.grottworkshop.gwswizardpager.ui.GeoFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Bundle args = getArguments();//from w w w . j av a2 s. c o m mKey = args.getString(ARG_KEY); mPage = mCallbacks.onGetPage(mKey); mGeocoder = new Geocoder(getActivity()); }
From source file:com.vishnuvalleru.travelweatheralertsystem.MainActivity.java
@SuppressLint("NewApi") @Override//from w w w. j a v a2s. c om protected void onCreate(Bundle savedInstanceState) { Bundle b = getIntent().getExtras(); String fromLocation = b.getString("from"); String toLocation = b.getString("to"); Geocoder coder = new Geocoder(this); StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); try { ArrayList<Address> frmAddresses = (ArrayList<Address>) coder.getFromLocationName(fromLocation, 50); ArrayList<Address> toAddresses = (ArrayList<Address>) coder.getFromLocationName(toLocation, 50); for (Address add : frmAddresses) { src_long = add.getLongitude(); src_lat = add.getLatitude(); } for (Address add : toAddresses) { dest_long = add.getLongitude(); dest_lat = add.getLatitude(); } } catch (IOException e) { e.printStackTrace(); } LatLng srcLatLng = new LatLng(src_lat, src_long); LatLng destLatLng = new LatLng(dest_lat, dest_long); super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); FragmentManager myFragmentManager = getFragmentManager(); MapFragment myMapFragment = (MapFragment) myFragmentManager.findFragmentById(R.id.map); myMap = myMapFragment.getMap(); myMap.setInfoWindowAdapter(new PopupAdapter(getLayoutInflater())); myMap.setOnMapClickListener(new OnMapClickListener() { @Override public void onMapClick(LatLng point) { // Drawing marker on the map drawMarker(point); } }); // Enabling MyLocation in Google Map myMap.setMyLocationEnabled(true); myMap.getUiSettings().setZoomControlsEnabled(true); myMap.getUiSettings().setCompassEnabled(true); myMap.getUiSettings().setMyLocationButtonEnabled(true); myMap.getUiSettings().setAllGesturesEnabled(true); myMap.setTrafficEnabled(true); myMap.animateCamera(CameraUpdateFactory.newLatLngZoom(destLatLng, 6)); markerOptions = new MarkerOptions(); drawMarker(srcLatLng); drawMarker(destLatLng); connectAsyncTask _connectAsyncTask = new connectAsyncTask(); _connectAsyncTask.execute(); }
From source file:com.duy.pascal.interperter.libraries.android.gps.AndroidLocationLib.java
public AndroidLocationLib(AndroidLibraryManager manager) { if (manager.getContext() != null) { mContext = manager.getContext(); mGeocoder = new Geocoder(mContext); mLocationManager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE); mLocationUpdates = new HashMap<>(); }/*from www . j av a 2 s . c o m*/ }
From source file:group5.trackerexpress.BasicMapActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent intent = this.getIntent(); intentDestination = intent.getStringExtra("destination"); intentLatLng = intent.getParcelableExtra("latlng"); System.out.println("Recieving destination: " + intentDestination + " " + intentLatLng); mGeocoder = new Geocoder(this); setContentView(R.layout.activity_map); // Get a rectangle covering 60% of the width and 60% of the height of the window, // from the center, that is used in checking when to deselect the marker windowRect = new Rect(); this.findViewById(android.R.id.content).getWindowVisibleDisplayFrame(windowRect); int widthOffset = Math.round(0.20f * windowRect.width()); int heightOffset = Math.round(0.20f * windowRect.height()); windowRect.set(windowRect.left + widthOffset, windowRect.top + heightOffset, windowRect.right - widthOffset, windowRect.bottom - heightOffset); MapFragment mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.map); mapFragment.getMapAsync(this); }
From source file:com.google.android.apps.muzei.gallery.GalleryArtSource.java
@Override public void onCreate() { super.onCreate(); mGeocoder = new Geocoder(this); mContentObserver = new ContentObserver(new Handler()) { @Override// w w w .ja v a 2 s. c o m public void onChange(boolean selfChange, Uri uri) { // Update the metadata updateMeta(); // See if we've just added the very first image Artwork currentArtwork = getCurrentArtwork(); if (currentArtwork == null) { publishNextArtwork(null); return; } // See if the current artwork was removed Cursor data = getContentResolver().query(GalleryContract.ChosenPhotos.CONTENT_URI, new String[] { BaseColumns._ID }, GalleryContract.ChosenPhotos.COLUMN_NAME_URI + "=?", new String[] { currentArtwork.getToken() }, null); if (data == null || !data.moveToFirst()) { // We're showing a removed URI publishNextArtwork(null); } if (data != null) { data.close(); } } }; // Make any changes since the last time the GalleryArtSource was created mContentObserver.onChange(false, GalleryContract.ChosenPhotos.CONTENT_URI); getContentResolver().registerContentObserver(GalleryContract.ChosenPhotos.CONTENT_URI, true, mContentObserver); }