uses-permission android:name= android.permission.ACCESS_FINE_LOCATION /uses-permission
private voidopenGPSSettings() {
LocationManager alm = (LocationManager)this
.getSystemService(Context.LOCATION_SERVICE);
if (alm
.isProviderEnabled(android.location.LocationManager.GPS_PROVIDER)) {
Toast.makeText(this, GPS模块正常 ,Toast.LENGTH_SHORT)
.show();
return;
}
Toast.makeText(this, 请开启GPS! ,Toast.LENGTH_SHORT).show();
Intent intent = newIntent(Settings.ACTION_SECURITY_SETTINGS);
startActivityForResult(intent,0); //此为设置完成后返回到获取界面
}
private voidgetLocation()
{
// 获取位置管理服务
LocationManager locationManager;
String serviceName = Context.LOCATION_SERVICE;
locationManager = (LocationManager)this.getSystemService(serviceName);
// 查找到服务信息
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); // 获取GPS信息
Location location =locationManager.getLastKnownLocation(provider); // 通过GPS获取位置
updateToNewLocation(location);
// 设置监听*器,自动更新的最小时间为间隔N秒(1秒为1*1000,这样写主要为了方便)或最小位移变化超过N米
locationManager.requestLocationUpdates(provider,100 * 1000, 500,
locationListener); }
private voidupdateToNewLocation(Location location) {
TextView tv1;
tv1 = (TextView)this.findViewById(R.id.tv1);
if (location != null) {
double latitude = location.getLatitude();
double longitude=location.getLongitude();
tv1.setText( 维度: + latitude+ \n经度 +longitude);
} else {
tv1.setText( 无法获取地理信息 );
}
}
public classWiFiInfoManager implements Serializable {
private static final long serialVersionUID= -4582739827003032383L;
private Context context;
public WiFiInfoManager(Context context) {
super();
this.context = context;
}
public WifiInfo getWifiInfo() {
WifiManager manager = (WifiManager)context
.getSystemService(Context.WIFI_SERVICE);
WifiInfo info = new WifiInfo();
info.mac =manager.getConnectionInfo().getBSSID();
Log.i( TAG , WIFI MACis: + info.mac);
return info;
}
public class WifiInfo {
public String mac;
public WifiInfo() {
super();
}
}
}
public staticLocation getWIFILocation(WifiInfo wifi) {
if (wifi == null) {
Log.i( TAG , wifiis null. );
return null;
}
DefaultHttpClient client = newDefaultHttpClient();
HttpPost post = new HttpPost( http://www.google.com/loc/json );
JSONObject holder = new JSONObject();
try {
holder.put( version , 1.1.0 );
holder.put( host , maps.google.com );
JSONObject data;
JSONArray array = new JSONArray();
if (wifi.mac != null wifi.mac.trim().length() 0) {
data = new JSONObject();
data.put( mac_address , wifi.mac);
data.put( signal_strength , 8);
data.put( age , 0);
array.put(data);
}
holder.put( wifi_towers ,array);
Log.i( TAG , request json: + holder.toString());
StringEntity se = newStringEntity(holder.toString());
post.setEntity(se);
HttpResponse resp =client.execute(post);
int state =resp.getStatusLine().getStatusCode();
if (state == HttpStatus.SC_OK) {
HttpEntity entity =resp.getEntity();
if (entity != null) {
BufferedReader br = newBufferedReader(
newInputStreamReader(entity.getContent()));
StringBuffer sb = newStringBuffer();
String resute = ;
while ((resute =br.readLine()) != null) {
sb.append(resute);
}
br.close();
Log.i( TAG , response json: + sb.toString());
data = newJSONObject(sb.toString());
data = (JSONObject)data.get( location );
Location loc = newLocation(
android.location.LocationManager.NETWORK_PROVIDER);
loc.setLatitude((Double)data.get( latitude ));
loc.setLongitude((Double)data.get( longitude ));
loc.setAccuracy(Float.parseFloat(data.get( accuracy )
.toString()));
loc.setTime(System.currentTimeMillis());
return loc;
} else {
return null;
}
} else {
Log.v( TAG , state + );
return null;
}
} catch (Exception e) {
Log.e( TAG ,e.getMessage());
return null;
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有