对于不使用任何第三方地图sdk的设备,可以直接获取gps传感器,基站传感器,wifi传感器所获取的经纬度,一般写一个service放在后台,代码如下
import android.app.IntentService;
import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
public class LocationUpdateService extends IntentService {
private final int MAX_DIVIDER = 600000;
private final int MIN_DIVIDER = 15000;
private final int PROVIDER_DISABLED = 3000;
private ArrayList<String> PROVIDER_ARRAY;
public static double latitude = 0d;//用于记录当前的纬度
public static double longitude = 0d;//用于记录当前的经度
private boolean isDestory;
private String locationProvider;
private LocationManager locationManager;
private LocationListener gpsLocationListener = new LocationListener() {
@Override
public void onLocationChanged(Location location) {
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public void onProviderEnabled(String provider) {
getBestLocationProvider();
}
@Override
public void onProviderDisabled(String provider) {
getBestLocationProvider();
}
};
private LocationListener networkLocationListener = new LocationListener() {
@Override
public void onLocationChanged(Location location) {
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public void onProviderEnabled(String provider) {
getBestLocationProvider();
}
@Override
public void onProviderDisabled(String provider) {
getBestLocationProvider();
}
};
private