androidgps源代码(android开源协议gpl)
admin 发布:2022-12-19 11:50 112
本篇文章给大家谈谈androidgps源代码,以及android开源协议gpl对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
- 1、android 求一个简单的使用GPS获取经纬度的代码
- 2、Android 怎么使用代码打开GPS
- 3、android中如何代码打开GPS,求代码!!!
- 4、求Android GPS的完全代码啊,现老是取不到坐标!!!
android 求一个简单的使用GPS获取经纬度的代码
private Context mContext;
private LocationManager locationManager;
public GPSTools(Context context) {
super();
mContext = context;
locationManager = (LocationManager) context
.getSystemService(Context.LOCATION_SERVICE);
}
/**
* 获取地址的经纬度
*
* @return 维度_经度
*/
public String getGpsAddress() {
// 返回所有已知的位置提供者的名称列表,包括未获准访问或调用活动目前已停用的。
ListString lp = locationManager.getAllProviders();
for (String item : lp) {
MLog.i("8023", "可用位置服务:" + item);
}
Criteria criteria = new Criteria();
criteria.setCostAllowed(false);
// 设置位置服务免费
criteria.setAccuracy(Criteria.ACCURACY_COARSE); // 设置水平位置精度
// getBestProvider 只有允许访问调用活动的位置供应商将被返回
String providerName = locationManager.getBestProvider(criteria, true);
MLog.i("8023", "------位置服务:" + providerName);
if (providerName != null) {
Location location = locationManager
.getLastKnownLocation(providerName);
if (location != null)
return "纬度:" + location.getLatitude() + " 经度:"
+ location.getLongitude();
} else {
Toast.makeText(mContext, "1.请检查网络连接 \n2.请打开我的位置",
Toast.LENGTH_SHORT).show();
}
return "未能获取到当前位置,请检测以下设置:\n1.检查网络连接 \n2.打开我的位置(GPS)";
}
Android 怎么使用代码打开GPS
public void setGpsState()
{
// 打开GPS
Settings.Secure.setLocationProviderEnabled(getContentResolver(),
LocationManager.GPS_PROVIDER, true);
}
网上说是需要root或程序安装到System/app
private void setGpsState2()
{
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(this, 0, gpsIntent, 0).send();
}
catch (CanceledException e)
{
e.printStackTrace();
}
}
这种好像2.2以上不可以用
android中如何代码打开GPS,求代码!!!
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivityForResult(intent, flag);
这样写就跳转到系统打开gps的界面了,不知道是不是你要找的,不过你可以试试。别忘了设置权限
求Android GPS的完全代码啊,现老是取不到坐标!!!
先在manifest里面配置 uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/
做一个button在OnClick事件里面写
LocationManager locationmanager=(LocationManager) Location01Activity.this.getSystemService(Context.LOCATION_SERVICE);
//作用:1定义当前所使用的LocationProvider,后面的参数,一个是时间(间隔的最小时间,毫秒单位,更新位置,但是为了保存电量间隔可能比这个大也可能比这个小)
//两次定位的最小距离,单位是米
locationmanager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, new TestLocationListener());
//如果如下设置,则用户需要移动5000米并过5秒后才会显示
// locationmanager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000, 5000, new TestLocationListener());
再定义一个类
class TestLocationListener implements LocationListener{
@Override
public void onLocationChanged(Location arg0) {
System.out.println(arg0.getLongitude());//经度
System.out.println(arg0.getLatitude());//纬度
}
//当数据的提供者不能用的时候
@Override
public void onProviderDisabled(String arg0) {
}
//当数据的提供者能用的时候
@Override
public void onProviderEnabled(String arg0) {
}
@Override
public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
}
}
关于androidgps源代码和android开源协议gpl的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。
版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;
- 上一篇:个人qq客服代码(号客服是多少)
- 下一篇:电影资源采集播放器代码(影视采集站源码)
相关推荐
- 05-07pb超级报表源代码(pb报表工具)[20240507更新]
- 05-07简历源代码可以上传照片的简单介绍[20240507更新]
- 05-07广告切换源代码免费下载(广告切换源代码免费下载安装)[20240507更新]
- 05-06阁楼网源代码(阁楼是什么网站)[20240506更新]
- 05-06源代码管理资源管理器(资源管理器运行代码)[20240506更新]
- 05-06人脸识别源代码pdf的简单介绍[20240506更新]
- 05-06包含超市管理系统java源代码的词条[20240506更新]
- 05-06商城app源代码免费(商城App源码)[20240506更新]
- 05-06包含游戏源代码不同的模式的词条[20240506更新]
- 05-06matlab写的图象灰度切分源代码(matlab灰度图像分段线性变换)[20240506更新]
取消回复欢迎 你 发表评论:
- 标签列表
- 最近发表
- 友情链接