【问题标题】:how to get current location Gmaps V2 ..?如何获取当前位置 Gmaps V2 ..?
【发布时间】:2013-07-23 06:38:31
【问题描述】:

我是 android 新手,我想显示我当前的位置,例如“巴基斯坦拉合尔 johar 镇”。有什么帮助吗?

提前致谢。

【问题讨论】:

    标签: android google-maps gps


    【解决方案1】:

    获取当前经纬度使用:LocationManager

    LocationManager locationmanager = (LocationManager) getSystemService(LOCATION_SERVICE);
            Criteria cr = new Criteria();
            String provider = locationmanager.getBestProvider(cr, true);
            Location location = locationmanager.getLastKnownLocation(provider);
            if (location != null) {
                double lat=location.getLatitude();
            double lng=location.getLongitude();
            }
    

    将当前的纬度和经度传递给以下方法,它将返回您的地址!

    public List<Address> getAddress(double latitude, double longitude) {
            List<Address> addresses = null;
            try {
    
                Geocoder geocoder;
    
                geocoder = new Geocoder(youractivityname.this);
                if (latitude != 0 || longitude != 0) {
                    addresses = geocoder.getFromLocation(latitude, longitude, 1);
    
                    //testing address below 
    
                    String address = addresses.get(0).getAddressLine(0);
                    String city = addresses.get(0).getAddressLine(1);
                    String country = addresses.get(0).getAddressLine(2);
                    Log.d("TAG", "address = " + address + ", city =" + city
                            + ", country = " + country);
    
                }
    
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                // Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
            }
            return addresses;
        }
    

    【讨论】:

    • List
      和 passangerHome.this 未知。?
    • passangerHome.this=youractivityname.this
    • 导入 java.util.List;
    • 导入android.location.Address;
    • 检查您设备中的 gps 是否已打开。那么只有你可以得到当前位置的经纬度。
    【解决方案2】:

    首先您必须找到您的位置,因此请关注以下帖子: Current location 和这里Current location

    然后找地方,看看这里 List of places around user

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-11-16
      • 2016-03-06
      • 1970-01-01
      • 1970-01-01
      • 2017-04-01
      • 1970-01-01
      相关资源
      最近更新 更多