LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE); Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER); double longitude = location.getLongitude(); double latitude = location.getLatitude();
@Override public void onLocationChanged(Location location) { if( mListener != null ) { mListener.onLocationChanged( location ); //Move the camera to the user's location and zoom in! mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(), location.getLongitude()), 12.0f)); } }
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Criteria criteria = new Criteria(); Location location = locationManager.getLastKnownLocation(locationManager.getBestProvider(criteria, false)); if (location != null) { map.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(), location.getLongitude()), 13)); CameraPosition cameraPosition = new CameraPosition.Builder() .target(new LatLng(location.getLatitude(), location.getLongitude())) // Sets the center of the map to location user .zoom(17) // Sets the zoom .bearing(90) // Sets the orientation of the camera to east .tilt(40) // Sets the tilt of the camera to 30 degrees .build(); // Creates a CameraPosition from the builder map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); }
.getSystemService(Context.LOCATION_SERVICE); locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000, 5, listener); Log.e("latitude", location.getLatitude() + ""); Log.e("longitude", location.getLongitude() + ""); jsonObject.put("latitude", location.getLatitude()); jsonObject.put("longitude", location.getLongitude());
lm =(LocationManager) getSystemService(Context.LOCATION_SERVICE); Criteria crit = new Criteria(); towers = lm.getBestProvider(crit, false); Location location = lm.getLastKnownLocation(towers); if(location != null){ Double glat = location.getLatitude(); Double glon = location.getLongitude(); }
LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE); Criteria criteria = new Criteria(); String provider = service.getBestProvider(criteria, false); Location location = service.getLastKnownLocation(provider); LatLng userLocation = new LatLng(location.getLatitude(),location.getLongitude());
private double[] getGPS() { LocationManager lm = (LocationManager) getSystemService( Context.LOCATION_SERVICE); List<String> providers = lm.getProviders(true); Location l = null; for (int i=providers.size()-1; i>=0; i--) { l = lm.getLastKnownLocation(providers.get(i)); if (l != null) break; } double[] gps = new double[2]; if (l != null) { gps[0] = l.getLatitude(); gps[1] = l.getLongitude(); } return gps; }
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 4000, 0, listener); locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 4000, 0, listener); loc.getLatitude(); loc.getLongitude(); intent.putExtra("Latitude", loc.getLatitude()); intent.putExtra("Longitude", loc.getLongitude()); intent.putExtra("Provider", loc.getProvider()); sendBroadcast(intent);
@Override public void onLocationChanged(Location location) { if( mListener != null ) { mListener.onLocationChanged( location ); LatLngBounds bounds = this.mMap.getProjection().getVisibleRegion().latLngBounds; if(!bounds.contains(new LatLng(location.getLatitude(), location.getLongitude()))) { //Move the camera to the user's location if they are off-screen! mMap.animateCamera(CameraUpdateFactory.newLatLng(new LatLng(location.getLatitude(), location.getLongitude()))); } } }
try { Criteria criteria = new Criteria(); mLocationManagerHelper.SetLocationManager((LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE)); mLocationManagerHelper.GetLocationManager().requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000L, 500.0f, mLocationManagerHelper.GetLocationListener()); String provider = mLocationManagerHelper.GetLocationManager().getBestProvider(criteria, false); Location location = mLocationManagerHelper.GetLocationManager().getLastKnownLocation(provider); if (location != null) { mLongitude = location.getLongitude(); mLatitude = location.getLatitude(); } } catch (Exception ex) { Log.e(TAG, "GPS", ex); }
private void _getLocation() { // Get the location manager LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); Criteria criteria = new Criteria(); String bestProvider = locationManager.getBestProvider(criteria, false); Location location = locationManager.getLastKnownLocation(bestProvider); try { lat = location.getLatitude(); lon = location.getLongitude(); } catch (NullPointerException e) { lat = -1.0; lon = -1.0; } }
Location lastKnownLocation = locationManager.getLastKnownLocation(locationProvider); urlString.append( Double.toString(lastKnownLocation.getLatitude() )); urlString.append(","); urlString.append( Double.toString(lastKnownLocation.getLongitude() )); urlString.append("&daddr=");//to urlString.append( Double.toString((double)dest[0]/1.0E6 )); GeoPoint currentPoint = new GeoPoint( new Double(lastKnownLocation.getLatitude()*1E6).intValue() ,new Double(lastKnownLocation.getLongitude()*1E6).intValue() );
mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); mLocationManager.requestLocationUpdates( LocationManager.NETWORK_PROVIDER, 0, 0, mVeggsterLocationListener); public void onLocationChanged(Location location) { int lat = (int) location.getLatitude(); // * 1E6); int log = (int) location.getLongitude(); // * 1E6); int acc = (int) (location.getAccuracy()); lati = location.getLatitude(); longi = location.getLongitude();
public void onLocationChanged(Location location) { currentLatitude = location.getLatitude(); currentLongitude = location.getLongitude();
Criteria cri= new Criteria(); String bbb = locationmanager.getBestProvider(cri, true); Location myLocation = locationmanager.getLastKnownLocation(bbb); double lat= myLocation.getLatitude(); double long = myLocation.getLongitude(); LatLng ll = new LatLng(lat, long); mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(ll, 20));
LocationManager locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE); String provider = locationManager.getBestProvider(new Criteria(), true); Location locations = locationManager.getLastKnownLocation(provider); List<String> providerList = locationManager.getAllProviders(); if(null!=locations && null!=providerList && providerList.size()>0){ double longitude = locations.getLongitude(); double latitude = locations.getLatitude(); Geocoder geocoder = new Geocoder(getApplicationContext(), Locale.getDefault()); try { List<Address> listAddresses = geocoder.getFromLocation(latitude, longitude, 1); if(null!=listAddresses&&listAddresses.size()>0){ String _Location = listAddresses.get(0).getAddressLine(0); } } catch (IOException e) { e.printStackTrace(); } }
// getLocationButton is the name of your button. Not the best name, I know. getLocationButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // instantiate the location manager, note you will need to request permissions in your manifest LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); // get the last know location from your location manager. Location location= locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); // now get the lat/lon from the location and do something with it. nowDoSomethingWith(location.getLatitude(), location.getLongitude()); } });
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000L, 10F, this); locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 5000L, 10F, this); mMap.animateCamera(CameraUpdateFactory.newLatLng(new LatLng(location.getLatitude(), location.getLongitude())));
Toast.makeText( getBaseContext(), "Location changed: Lat: " + loc.getLatitude() + " Lng: " + loc.getLongitude(), Toast.LENGTH_SHORT).show(); String longitude = "Longitude: " + loc.getLongitude(); Log.v(TAG, longitude); String latitude = "Latitude: " + loc.getLatitude(); Log.v(TAG, latitude); List<Address> addresses; try { addresses = gcd.getFromLocation(loc.getLatitude(), loc.getLongitude(), 1); if (addresses.size() > 0) { System.out.println(addresses.get(0).getLocality());
Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_COARSE); String bestProvider = lm.getBestProvider(criteria, true); Location loc = lm.getLastKnownLocation(bestProvider); lat = loc.getLatitude(); lng = loc.getLongitude();