Example usage for android.content Context LOCATION_SERVICE

List of usage examples for android.content Context LOCATION_SERVICE

Introduction

In this page you can find the example usage for android.content Context LOCATION_SERVICE.

Prototype

String LOCATION_SERVICE

To view the source code for android.content Context LOCATION_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.location.LocationManager for controlling location updates.

Usage

From source file:com.example.amapapplicationtest.MainActivity.java

/** Called when the activity is first created. */
@Override/*from  w  w  w .  ja v a 2s . c  om*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    initMap();

    LocationManager lm = (LocationManager) getSystemService(LOCATION_SERVICE);
    String provider = lm.getBestProvider(new Criteria(), true);

    LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    Criteria criteria = new Criteria();

    Location location = locationManager.getLastKnownLocation(locationManager.getBestProvider(criteria, false));
    if (location != null) {
        googlemap.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
        googlemap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));

    }

    if (provider == null) {
        onProviderDisabled(provider);
    }
    data = new MarkerDataSource(context);
    try {
        data.open();

    } catch (Exception e) {
        Log.i("hello", "hello");
    }

    List<MyMarkerObj> m = data.getMyMarkers();
    for (int i = 0; i < m.size(); i++) {
        String[] slatlng = m.get(i).getPosition().split(" ");
        LatLng lat = new LatLng(Double.valueOf(slatlng[0]), Double.valueOf(slatlng[1]));
        googlemap.addMarker(
                new MarkerOptions().title(m.get(i).getTitle()).snippet(m.get(i).getSnippet()).position(lat));

        googlemap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {

            public void onInfoWindowClick(Marker marker) {
                Toast.makeText(getBaseContext(), "Info Window clicked@" + marker.getId(), Toast.LENGTH_SHORT)
                        .show();
            }
        });

        //  marker.view();
        //    data.getMarker(new MyMarkerObj(marker.getTitle(), marker.getSnippet(), marker.getPosition().latitude + " " + marker.getPosition().longitude));
    }

    googlemap.setOnMapLongClickListener(new GoogleMap.OnMapLongClickListener() {

        public void onMapLongClick(final LatLng latlng) {
            LayoutInflater li = LayoutInflater.from(context);
            final View v = li.inflate(R.layout.alertlayout, null);
            AlertDialog.Builder builder = new AlertDialog.Builder(context);
            builder.setView(v);
            builder.setCancelable(false);

            builder.setPositiveButton("Create", new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int which) {
                    EditText title = (EditText) v.findViewById(R.id.ettitle);
                    EditText snippet = (EditText) v.findViewById(R.id.etsnippet);
                    googlemap.addMarker(new MarkerOptions().title(title.getText().toString())
                            .snippet(snippet.getText().toString())
                            .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE))
                            .position(latlng));
                    String sll = latlng.latitude + " " + latlng.longitude;
                    data.addMarker(
                            new MyMarkerObj(title.getText().toString(), snippet.getText().toString(), sll));
                }
            });

            builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            });

            AlertDialog alert = builder.create();
            alert.show();

        }
    });
}

From source file:com.binomed.showtime.android.util.localisation.LocationUtils.java

private static LocationManager getLocationManager(Context context) {
    return (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
}

From source file:com.hoccer.api.android.LinccLocationManager.java

public LinccLocationManager(Context pContext, AsyncLinccer linccer, Updateable updater) {
    mContext = pContext;/*from   w  w  w  .ja va  2  s.  com*/

    mLinccer = linccer;
    mUpdater = updater;

    mLocationManager = (LocationManager) pContext.getSystemService(Context.LOCATION_SERVICE);
    mWifiManager = (WifiManager) pContext.getSystemService(Context.WIFI_SERVICE);

    mNetworkProviderAvailable = mLocationManager.getAllProviders().contains(LocationManager.NETWORK_PROVIDER);
}

From source file:me.ziccard.secureit.async.upload.PeriodicPositionUploaderTask.java

/**
 * Constructor//from  w ww .  j  av  a2  s  .  c  om
 * @param context
 * @param lat
 * @param lng
 */
public PeriodicPositionUploaderTask(Context context) {
    this.context = context;
    locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);

    if (locationManager.getAllProviders().contains(LocationManager.NETWORK_PROVIDER))
        locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
    if (locationManager.getAllProviders().contains(LocationManager.GPS_PROVIDER))
        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);

    prefs = new SecureItPreferences(context);

    this.phoneId = prefs.getPhoneId();
    this.accessToken = prefs.getAccessToken();
}

From source file:com.dycody.android.idealnote.utils.GeocodeHelper.java

private GeocodeHelper() {
    instance = this;
    locationManager = (LocationManager) IdealNote.getAppContext().getSystemService(Context.LOCATION_SERVICE);
}

From source file:com.findcab.driver.activity.Signup.java

private void initView() {
    context = this;
    back = (Button) findViewById(R.id.back);
    back.setOnClickListener(this);
    start = (Button) findViewById(R.id.start);
    start.setOnClickListener(this);

    edit_name = (EditText) findViewById(R.id.name);
    edit_mobile = (EditText) findViewById(R.id.mobile);
    edit_password = (EditText) findViewById(R.id.password);

    checkBox = (CheckBox) findViewById(R.id.checkBox);

    item = (TextView) findViewById(R.id.item);
    item.setOnClickListener(this);

    if (initGPS()) {

        LocationManager locationManager;
        String serviceName = Context.LOCATION_SERVICE;
        locationManager = (LocationManager) this.getSystemService(serviceName);
        // ?// w  ww. j av a2 s .com
        Criteria criteria = new Criteria();
        criteria.setAccuracy(Criteria.ACCURACY_FINE);
        criteria.setAltitudeRequired(false);
        criteria.setBearingRequired(false);
        criteria.setCostAllowed(true);
        criteria.setPowerRequirement(Criteria.POWER_LOW);

        String provider = locationManager.getBestProvider(criteria, true);
        location = locationManager.getLastKnownLocation(provider);
        if (location != null) {
            lat = location.getLatitude();
            lng = location.getLongitude();
        }
    }
}

From source file:br.com.split.activities.FacebookEscolherLocalActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    lifecycleHelper = new UiLifecycleHelper(this, new Session.StatusCallback() {
        @Override/*  w w  w.j a v a 2  s .c o  m*/
        public void call(Session session, SessionState state, Exception exception) {
            onSessionStateChanged(session, state, exception);
        }
    });
    lifecycleHelper.onCreate(savedInstanceState);

    ensureOpenSession();

    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    onClickGPS();
}

From source file:android.zetterstrom.com.snow.fragments.SnowFragment.java

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setRetainInstance(true);/* w w w .ja  v a 2 s .c  o  m*/
    mLocationManager = (LocationManager) SnowApplication.getAppContext()
            .getSystemService(Context.LOCATION_SERVICE);
    checkPermission();
}

From source file:de.longri.cachebox3.AndroidPlatformConnector.java

@Override
public void initialLocationReciver() {

    if (locationManager != null) {
        return;//from  w  w w.java 2 s . c om
    }

    locationListener = new AndroidLocationListener();

    // GPS
    // Get the location manager
    locationManager = (LocationManager) this.application.getSystemService(Context.LOCATION_SERVICE);

    final int updateTime = 500; //500ms

    //TODO get gps updateTime from settings
    //            int updateTime = Config.gpsUpdateTime.getValue();
    //
    //            Config.gpsUpdateTime.addChangedEventListener(new IChanged() {
    //
    //                @Override
    //                public void isChanged() {
    //                    int updateTime = Config.gpsUpdateTime.getValue();
    //                    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, updateTime, 1, this);
    //                }
    //            });

    application.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            try {
                locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, updateTime, 1,
                        locationListener);
                if (ActivityCompat.checkSelfPermission(AndroidPlatformConnector.this.application,
                        Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
                        && ActivityCompat.checkSelfPermission(AndroidPlatformConnector.this.application,
                                Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                    return;
                }
                locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 10000, 300,
                        locationListener);

                locationManager.addNmeaListener(locationListener);
                locationManager.addGpsStatusListener(locationListener);
            } catch (Exception e) {
                log.error("main.initialLocationManager()", e);
                e.printStackTrace();
            }
        }
    });

}

From source file:com.example.mohamed.a3qaqer.RegisterActvity.java

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.register_view);
    signup = (Button) findViewById(R.id.sign_up_register);
    name = (EditText) findViewById(R.id.name_edit_text);
    password = (EditText) findViewById(R.id.password_edit);
    phone = (EditText) findViewById(R.id.phone_edit_text);
    license = (EditText) findViewById(R.id.lisence_edit_text);
    address = (EditText) findViewById(R.id.address_edit_text);
    mFirebaseAuth = FirebaseAuth.getInstance();
    mProgressDialog = new ProgressDialog(this);
    mProgressDialog.setMessage("  ......");
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
        buildAlertMessageNoGps();/*  ww  w .  j a va 2 s.co m*/
    }
    mDatabaseReference = FirebaseDatabase.getInstance().getReference().child("pharmacies");
    signUp();
}