Map 简单示例反向地理编码osmdroid

Map 简单示例反向地理编码osmdroid,map,osmdroid,nominatim,Map,Osmdroid,Nominatim,我正在寻找一个使用osmdroid进行反向地理编码的简单示例。 我是否必须将MAPI与JSON等一起使用? 我听说使用Geocoder类做同样的事情,但似乎太简单了。。。 在尝试执行请求时,类RequestBuilder无法识别是否正常 提名 谢谢您可以使用课堂 下面是一个使用OSMBonusPack的示例: // declare your map somewhere in the Activity map = (MapView) findViewById(R.i

我正在寻找一个使用osmdroid进行反向地理编码的简单示例。 我是否必须将MAPI与JSON等一起使用? 我听说使用Geocoder类做同样的事情,但似乎太简单了。。。 在尝试执行请求时,类RequestBuilder无法识别是否正常 提名


谢谢

您可以使用课堂

下面是一个使用OSMBonusPack的示例:

        // declare your map somewhere in the Activity
        map = (MapView) findViewById(R.id.map);
        map.setTileSource(TileSourceFactory.MAPNIK);
        map.setMultiTouchControls(true);

        // create a GeoPoint
        final GeoPoint startPoint = new GeoPoint(36.716999, 3.042076);

        // Retreive Geocoding data (add this code to an event click listener on a button)
        new AsyncTask<Void, Void, Void>(){
            @Override
            protected Void doInBackground(Void... voids) {
                // Reverse Geocoding
                GeocoderNominatim geocoder = new GeocoderNominatim(userAgent);
                String theAddress;
                try {
                    List<Address> addresses = geocoder.getFromLocation(startPoint.getLatitude(), startPoint.getLongitude(), 1);
                    StringBuilder sb = new StringBuilder();
                    if (addresses.size() > 0) {
                        Address address = addresses.get(0);
                        int n = address.getMaxAddressLineIndex();
                        Log.d("Test", "CountryName: " + address.getCountryName());
                        Log.d("Test", "CountryCode: " + address.getCountryCode());
                        Log.d("Test", "PostalCode " + address.getPostalCode());
//                        Log.d("Test", "FeatureName " + address.getFeatureName()); //null
                        Log.d("Test", "City: " + address.getAdminArea());
                        Log.d("Test", "Locality: " + address.getLocality());
                        Log.d("Test", "Premises: " + address.getPremises()); //null
                        Log.d("Test", "SubAdminArea: " + address.getSubAdminArea());
                        Log.d("Test", "SubLocality: " + address.getSubLocality());
//                        Log.d("Test", "SubThoroughfare: " + address.getSubThoroughfare()); //null
//                        Log.d("Test", "getThoroughfare: " + address.getThoroughfare()); //null
                        Log.d("Test", "Locale: " + address.getLocale());
                        for (int i=0; i<=n; i++) {
                            if (i!=0)
                                sb.append(", ");
                            sb.append(address.getAddressLine(i));
                        }
                        theAddress = sb.toString();
                    } else {
                        theAddress = null;
                    }
                } catch (IOException e) {
                    theAddress = null;
                }
                if (theAddress != null) {
                    Log.d("Test", "Address: " + theAddress);
                }

                return null;
            }
        }.execute();
//在活动中的某个位置声明地图
map=(MapView)findviewbyd(R.id.map);
map.setTileSource(TileSourceFactory.MAPNIK);
map.setMultiTouchControls(真);
//创建一个地质点
最终地质点起始点=新地质点(36.716999,3.042076);
//检索地理编码数据(将此代码添加到事件中,单击按钮上的侦听器)
新建异步任务(){
@凌驾
受保护的空位背景(空位…空位){
//反向地理编码
GeocoderNominatim geocoder=新的GeocoderNominatim(用户代理);
字符串地址;
试一试{
列表
希望这有帮助