当前位置: 代码迷 >> Android >> android wifi定位设立
  详细解决方案

android wifi定位设立

热度:73   发布时间:2016-04-28 06:23:47.0
android wifi定位设置
android3.2系统怎么打开允许使用wifi定位?在位置和安全里没有这个选项?2.*和4.*的系统里都有这个选项的,在3.2里locationManager.isProviderEnable(LocationManager.NETWORK_PROVIDER)返回 null,有没有人遇到这种情况?
------解决方案--------------------
可以先判断下手机支持的定位的服务字符串,是否包含LocationManager.NETWORK_PROVIDER,然后再判断服务是否可用,在获取位置信息,如果返回为空的话,可以采用通过百度API获取位置的方式,我现在碰到的问题是,获取过来的经纬度信息不准,误差很大。
------解决方案--------------------
/**
 * 手机坐标定位的工具类
 * @author TCK-001
 * @version 1.0
 */
public final class PointUtil {

private PointUtil() {}
private static PointUtil bean = new PointUtil();
private double[] myPoint = new double[3];
private boolean isEditPoint = false;

/**
 * 经度
 * */
public static final String LONGITUDE = "longitude";

/**
 * 纬度
 * */
public static final String LATITUDE = "latitude";

/** 天安门的坐标 */
public static final GeoPoint CENTER_POINT = new GeoPoint((int) (39.945d * 1E6), (int) (116.404d * 1E6));

/**
 * 单例模式获得bean
 * @return FileUtil
 */
public static PointUtil get() {
return bean;
}

private LocationListener listener = new LocationListener() {

public void onStatusChanged(String provider, int status, Bundle extras) {
}

public void onProviderEnabled(String provider) {
}

public void onProviderDisabled(String provider) {
}

public void onLocationChanged(Location location) {
if (location != null) {
double[] old = myPoint;
myPoint = new double[] { location.getLongitude(), location.getLatitude(), location.getAltitude() };
if (myPoint[0] <= 0 
------解决方案--------------------
 myPoint[1] <= 0) {return;}
if (old[0] != myPoint[0] 
------解决方案--------------------
 old[1] != myPoint[1]) {
if (MapUtil.get().getDistance(old, myPoint) > 500) {
editMemberPoint();
SellerMarketService.get().loadNearby();
SellerMarketService.get().editDistance();
}
if (MapUtil.get().getDistance(old, myPoint) > 1000 
------解决方案--------------------
 ToolUtil.get().isBlank(Container.city)) {
RegionService.get().pointCity();
}
doCallback();
}
}
}

};

private BDLocationListener baiduListener = new BDLocationListener() {

public void onReceivePoi(BDLocation location) {
if (null == location) {return;}
}

public void onReceiveLocation(BDLocation location) {
if (location != null) {
double[] old = myPoint;
myPoint = new double[] { location.getLongitude(), location.getLatitude(), location.getAltitude() };
if (myPoint[0] <= 0 
------解决方案--------------------
 myPoint[1] <= 0) {return;}
if (old[0] != myPoint[0] 
------解决方案--------------------
 old[1] != myPoint[1]) {
if (MapUtil.get().getDistance(old, myPoint) > 500) {
editMemberPoint();
SellerMarketService.get().loadNearby();
SellerMarketService.get().editDistance();
}
if (MapUtil.get().getDistance(old, myPoint) > 1000 
------解决方案--------------------
 ToolUtil.get().isBlank(Container.city)) {
RegionService.get().pointCity();
}
doCallback();
}
}
}
};

// 注册一个普通坐标
private void plainReg() {
LocationManager manager = (LocationManager) pointContext.getSystemService(Context.LOCATION_SERVICE);
boolean isGps = manager.isProviderEnabled(LocationManager.GPS_PROVIDER);
boolean isNetWork = manager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if (!isGps 
------解决方案--------------------
 !isNetWork) {
Intent GPSIntent = new Intent(); 
GPSIntent.setClassName("com.android.settings", "com.android.settings.widget.SettingsAppWidgetProvider");
GPSIntent.addCategory("android.intent.category.ALTERNATIVE"); 
GPSIntent.setData(Uri.parse("custom:3"));
try {PendingIntent.getBroadcast(pointContext, 0, GPSIntent, 0).send();} catch (Exception e) {}
}
String provider = LocationManager.GPS_PROVIDER;
if (manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);// 获取精准位置
  相关解决方案