如何从地址获取经度和纬度?

时间:2018-09-24 15:53:16

标签: google-maps geolocation android-adapter android-fragmentactivity

背景:在我的应用中,我有一个recyclerView,每个视图都有一个地址。我希望用户点击地址,以便她可以通过意图打开地图应用。因此,我正在使用下面的函数传递上下文和地址来获取地理位置,然后将其传递到ACTION_VIEW以在Google地图中作为标记打开。但是,我在函数本身中遇到错误。这是函数:

        public LatLng getGeoLocation(Context context, String strAddress) {

        Geocoder coder = new Geocoder(context);
        List<Address> address;
        LatLng point = null;

        try {
            // May throw an IOException
            address = coder.getFromLocationName(strAddress, 1);

            double lat = address.get(0).getLatitude();
            double lon = address.get(0).getLongitude();
            point = new LatLng(lat, lon);

        } catch (IOException ex) {

            ex.printStackTrace();
        }
        return point;

我正在构建的错误是:

  

错误:类LatLng中的构造函数LatLng无法应用于给定类型;   必需:无参数   找到:双,双   原因:实际和正式论据列表的长度不同

我在做什么错了?

0 个答案:

没有答案
相关问题