Android Open Source - MultiLocation Location Service






From Project

Back to project page MultiLocation.

License

The source code is released under:

Apache License

If you think the Android project MultiLocation listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.example.owner;
/*from www.ja va2s  . c  o m*/
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.IBinder;

public class LocationService extends Service {
  
  protected LocationManager locationManager;
  Location location;
  
  private static final long MIN_DISTANCE_FOR_UPDATE = 10;
  private static final long MIN_TIME_FOR_UPDATE = 1000 * 60;
  
  public LocationService(Context context){
    locationManager = (LocationManager)context.getSystemService(LOCATION_SERVICE);
  }
  
  public Location getLocation(String provider,LocationListener locationListener){
    if(locationManager.isProviderEnabled(provider)){
      if(provider == LocationManager.GPS_PROVIDER)
        locationManager.requestLocationUpdates(provider, MIN_TIME_FOR_UPDATE, MIN_DISTANCE_FOR_UPDATE, locationListener);
      else if(provider == LocationManager.NETWORK_PROVIDER)
        locationManager.requestLocationUpdates(provider, 0, 0, locationListener);
      System.out.println("????1:"+provider);
    }
    
    if(locationManager != null){
      location = locationManager.getLastKnownLocation(provider);
      if(location != null){
        System.out.println("????2:???");
        return location;
      }
    }
    System.out.println("????2:???");
    return null;
  }

  @Override
  public IBinder onBind(Intent intent) {
    return null;
  }

}




Java Source Code List

com.example.owner.GPSLocation.java
com.example.owner.LagLng.java
com.example.owner.LocationBase.java
com.example.owner.LocationServiceProvider.java
com.example.owner.LocationService.java
com.example.owner.MainActivity.java
com.example.owner.NetworkLocation.java