android怎么用经纬度定位,android 根据经纬度定位所在城市
转自http://www.thinksaas.cn/group/topic/215488/,更改了他默认写死的经纬度,可以得到正确的定位
requires ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission.
package com.studio.android.chp08.ex01;
import java.io.IOException;
import java.util.List;
import android.app.Activity;
import android.content.Context;
import android.location.Address;
import android.location.Criteria;
import android.location.Geocoder;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.TextView;
public class CurrentLocation extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LocationManager locationManager;
String serviceName = Context.LOCATION_SERVICE;
locationManager = (LocationManager)getSystemService(serviceName);
// String provider = LocationManager.GPS_PROVIDER;
String provider = LocationManager.NETWORK_PROVIDER;
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);
Location location = locationManager.getLastKnownLocation(provider);
updateWithNewLocation(location);
locationManager.requestLocationUpdates(provider, 2000, 10,
locationListener);
}
private final LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
updateWithNewLocation(location);
}
public void onProviderDisabled(String provider){
updateWithNewLocation(null);
}
public void onProviderEnabled(String provider){ }
public void onStatusChanged(String provider, int status,
Bundle extras){ }
};
private void updateWithNewLocation(Location location) {
double lat = 0;
double lng = 0;
String latLongString;
TextView myLocationText;
myLocationText = (TextView) findViewById(R.id.myLocationText);
if (location != null) {
lat = location.getLatitude();
lng = location.getLongitude();
DecimalFormat df = new DecimalFormat("#.###");
//lat = df.format(lat);
//lng = df.format(lng);
//latLongString = "纬度:" + df.format(lat) + "n经度:" + df.format(lng);
latLongString = "纬度:" + lat + "n经度:" + lng;
} else {
latLongString = "无法获取地理信息";
}
List
addList = null;Geocoder ge = new Geocoder(this);
try {
//addList = ge.getFromLocation(24.463, 118.1, 1);
addList = ge.getFromLocation(lat, lng, 1);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(addList!=null && addList.size()>0){
for(int i=0; i
Address ad = addList.get(i);
latLongString +="n";
latLongString += ad.getCountryName() +";"+ ad.getLocality();
}
}
myLocationText.setText("您当前的位置是:n"+latLongString);
}
}
android怎么用经纬度定位,android 根据经纬度定位所在城市相关推荐
- 利用百度地图Android定位SDK获取经纬度
环境的搭建(参考上一次的文章) 百度地图Android定位SDK的使用 2.在Android studio里设计程序来获取经纬度 界面布局activity_main.xml文件的源代码: <?x ...
- android 百度坐标 gps,Android中gps定位不返回经纬度的解决方案
定位,算是android应用中一个非常常见的功能了吧,并且大部分的应用里基本也都会用到地图,所以以前的做法基本都是直接接入了百度.高德这些第三方定位,也没遇到过什么问题. 然而,最近的工作基本上都是做 ...
- Android定位获取当前经纬度
1.使用android提供的LocationManager管理类 2.使用GPS或者网络定位 3.只使用了Log打印出经纬度,没有在界面显示 public class MainActivity ext ...
- Android使用Google定位服务定位并将经纬度转换为详细地址信息(国省市县街道)
本文是作者在学习使用Google定位服务定位时的学习笔记,采用的是Kotlin语言编写. 1.位置权限以及定位服务 1.1 位置权限 1.2 动态权限申请 1.3 位置服务 1.4 APP权限与定位服 ...
- 百度定位 Android 经纬度出现4.9E-324 问题解决
百度sdk定位时,经纬度一直返回:4.9E-324 怎么办? 当你定位模式设置为:option.setCoorType("bd09ll"); 就有可能出现这个情况,如何破? 将你 ...
- Android 集成高德定位功能,获取经纬度,城市至门牌号码
老规矩,上效果图,先给你们看下效果: 虽然打上了马赛克,但是装到别人手机上还是看着很爽啊; 友善提醒:禁止用作非法用途 首先进入高德地图开放平台 先要下载高德的定位SDK包,这里就不演示了 1.--- ...
- Android使用百度地图api获取定位信息(经纬度)
文章目录 注册 申请密钥 配置 使用 遇到问题 注册 登录百度地图开放平台 注册百度地图开发者,填写相关信息 提交成功后收到邮件 点击链接弹出如下提示就算激活成功了 申请密钥 点击申请密钥或者创建应用 ...
- Android 调用原生API获取地理位置和经纬度,判断所在国家
public static boolean isCN(Context context) {TelephonyManager tm = (TelephonyManager) context.getSys ...
- android 基站经纬度,android手机获取gps和基站的经纬度地址实现代码
代码如下: 代码如下: package com.talkweb.mobileapp; import java.text.DecimalFormat; import android.app.Activi ...
- Android之应用APN、WIFI、GPS定位小例子
转自一个网上项目,由于是例子打包下载,出处不详.例子中自我写入注释. Activity类: package com.maxtech.common; import com.maxtech.common. ...
最新文章
- 在 Ubuntu 环境下实现插入鼠标自动关闭触摸板
- shiro的会话管理:介绍
- HDLBits答案(13)_Verilog移位寄存器附加题
- 关系数据库理论:数据库的六大范式知识笔记
- 小程序 | 基于WAMP的新闻网小程序开发(体验全栈式开发微信小程序)
- webpack常用知识点
- AI产品开发的核心原则:以研究为核心驱动
- jj为什么会变大变小_胡杏儿怀二胎不解鼻子为何变大?其实,还有三个部位变大的更厉害...
- CSDN 输入公式的方法
- SAS时间序列分析案例--有季节效应的非平稳序列分析
- 30分钟做一个二维码名片应用,有源码!
- java中的NIO是什么?
- 在Excel里怎么输入可以打钩的选择框?
- redis实战【西橙先生】
- 内存屏障 Memery Barrier
- 独家|数据造假、爬虫与反爬虫战争暴露出哪些行业现状?
- [踩坑解决]npm ERR! gyp info it worked if it ends with oknpm ERR! gyp verb cli [
- 建筑施工技术【22】
- linux下写脚本时-gt或-lt是什么意思?
- 对象及日期定时器、延时器
热门文章
- 密码学应用的四个进化阶段
- 天龙八部稳定服务器,献给天龙八部Online的Fans们--职业玩家及所在服务器
- Phase2 Day2 数组和链表
- D7000、60D、K5、E5的详细对比评价(转)
- 杭州软件测试工程师培训
- U磁盘检测和大量收集量产工具
- Mac如何用Boot Camp安装Windows 11?告诉你如何安装 能不能安装!
- NetMeeting的使用
- 【Excel,遗忘密码后如何撤销工作表保护密码】
- [ CSOL ] - zihao + 自适应 + 文字滚动 + 媒体查询 + fullpage + 手风琴 + 延时动画