Android根据已知的经纬度坐标获取当前位置

例如:经度:10.123456   纬度:20.654321

           

根据以上坐标获取到实际位置(不借用百度地图或高德地图的API)


代码如下:

  1. //放入经纬度就可以了
  2. public String getAddress(double latitude, double longitude) {
  3. Geocoder geocoder = new Geocoder( this, Locale.getDefault());
  4. try {
  5. List<Address> addresses = geocoder.getFromLocation(latitude,
  6. longitude, 1);
  7. if (addresses.size() > 0) {
  8. Address address = addresses.get( 0);
  9. String data = address.toString();
  10. int startCity = data.indexOf( "1:\"") + "1:\"".length();
  11. int endCity = data.indexOf( "\"", startCity);
  12. String city = data.substring(startCity, endCity);
  13. int startPlace = data.indexOf( "feature=") + "feature=".length();
  14. int endplace = data.indexOf( ",", startPlace);
  15. String place = data.substring(startPlace, endplace);
  16. return city + place ;
  17. }
  18. } catch (IOException e) {
  19. e.printStackTrace();
  20. }
  21. return "获取失败";
  22. }



本文出自 “移动平台开发” 博客,请务必保留此出处http://liuxudong1001.blog.51cto.com/10877072/1749869

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值