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)); }
Criteria myCriteria = new Criteria(); myCriteria.setAccuracy(Criteria.ACCURACY_HIGH); myCriteria.setPowerRequirement(Criteria.POWER_LOW); // let Android select the right location provider for you String myProvider = locationManager.getBestProvider(myCriteria, true); // finally require updates at -at least- the desired rate long minTimeMillis = 600000; // 600,000 milliseconds make 10 minutes locationManager.requestLocationUpdates(myProvider,minTimeMillis,0,locationListener);
Criteria criteria = new Criteria(); String provider = locationManager.getBestProvider(criteria, true); Location location = locationManager.getLastKnownLocation(provider);
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); // Creating a criteria object to retrieve provider Criteria criteria = new Criteria(); // Getting the name of the best provider String provider = locationManager.getBestProvider(criteria, true); // Getting Current Location locationManager.requestLocationUpdates(provider, 10000L, 1f, (LocationListener) this);
public class MyActivity extends MapActivity implements LocationListener { private LocationManager locationManager; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); requestFineAccuracyLocationUpdates(); } private void requestFineAccuracyLocationUpdates() { Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); List<String> providers = locationManager.getProviders(true); for (String provider : providers) { locationManager.requestLocationUpdates(provider, 5000, 1000, this); } } @Override public void onLocationChanged(Location location) { /* You can get your latitude and longitude here, and do whatever. */ } }
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();
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());
LocationManager LM1=(LocationManager) getSystemService(Context.LOCATION_SERVICE); Criteria criteria = new Criteria(); String provider=LM1.getBestProvider(criteria, true); LM1.requestLocationUpdates(provider,0,1,this);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); provider = locationManager.getBestProvider(criteria, false); Location location = locationManager.getLastKnownLocation(provider); VehicleListener vl = new VehicleListener(); locationManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, vl); if (location != null) { System.out.println("Provider " + provider + " has been selected."); lat =location.getLatitude(); lon = 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));
Criteria c = new Criteria(); c.setAccuracy(Criteria.ACCURACY_COARSE);
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; } }
LocationManager lm = (LocationManager) getSystemService(LOCATION_SERVICE); String provider = lm.getBestProvider(new Criteria(), true); lm.requestLocationUpdates(provider, 10000, 0, this);
Button gpsButton = (Button)this.findViewById(R.id.buttonGPSLocation); gpsButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // Start loction service LocationManager locationManager = (LocationManager)[OUTERCLASS].this.getSystemService(Context.LOCATION_SERVICE); Criteria locationCritera = new Criteria(); locationCritera.setAccuracy(Criteria.ACCURACY_COARSE); locationCritera.setAltitudeRequired(false); locationCritera.setBearingRequired(false); locationCritera.setCostAllowed(true); locationCritera.setPowerRequirement(Criteria.NO_REQUIREMENT); String providerName = locationManager.getBestProvider(locationCritera, true); if (providerName != null && locationManager.isProviderEnabled(providerName)) { // Provider is enabled locationManager.requestLocationUpdates(providerName, 20000, 100, [OUTERCLASS].this.locationListener); } else { // Provider not enabled, prompt user to enable it Toast.makeText([OUTERCLASS].this, R.string.please_turn_on_gps, Toast.LENGTH_LONG).show(); Intent myIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); [OUTERCLASS].this.startActivity(myIntent); } } });
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); LocationListener loc_listener = new LocationListener() { public void onLocationChanged(Location l) {} public void onProviderEnabled(String p) {} public void onProviderDisabled(String p) {} public void onStatusChanged(String p, int status, Bundle extras) {} }; locationManager .requestLocationUpdates(bestProvider, 0, 0, loc_listener); location = locationManager.getLastKnownLocation(bestProvider); try { lat = location.getLatitude(); lon = location.getLongitude(); } catch (NullPointerException e) { lat = -1.0; lon = -1.0; } }
Criteria criteria = new Criteria(); LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); // mMap.addMarker(new MarkerOptions().position(sydney2).title("fi")); if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // TODO: Consider calling // ActivityCompat#requestPermissions // here to request the missing permissions, and then overriding // public void onRequestPermissionsResult(int requestCode, String[] permissions, // int[] grantResults) // to handle the case where the user grants the permission. See the documentation // for ActivityCompat#requestPermissions for more details. return; } locationManager.requestLocationUpdates(locationManager.getBestProvider(criteria, true), 2000, 0, new android.location.LocationListener() { @Override public void onLocationChanged(Location location) { // }
//All your normal criteria setup Criteria criteria = new Criteria(); //Use FINE or COARSE (or NO_REQUIREMENT) here criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setPowerRequirement(Criteria.POWER_LOW); criteria.setAltitudeRequired(true); criteria.setSpeedRequired(true); criteria.setCostAllowed(true); criteria.setBearingRequired(true); //API level 9 and up criteria.setHorizontalAccuracy(Criteria.ACCURACY_HIGH); criteria.setVerticalAccuracy(Criteria.ACCURACY_HIGH); criteria.setBearingAccuracy(Criteria.ACCURACY_LOW); criteria.setSpeedAccuracy(Criteria.ACCURACY_MEDIUM);
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(); } }
String mlocProvider; <br> Criteria hdCrit = new Criteria(); <br> hdCrit.setAccuracy(Criteria.ACCURACY_COARSE); <br> mlocProvider = mlocManager.getBestProvider(hdCrit, true); </br> </br> </br>