如何在Android中使用OpenStreetMap的获取经度和

如何在Android中使用OpenStreetMap的获取经度和

本文介绍了如何在Android中使用OpenStreetMap的获取经度和纬度的地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序,我使用OSM map.I有经度和纬度。
使用此方法

In my app i am using osm map.I have latitude and longitude.using this method

proj = mapView.getProjection();
        loc = (GeoPoint) proj.fromPixels((int) e.getX(), (int) e.getY());
        String longitude = Double
                .toString(((double) loc.getLongitudeE6()) / 1000000);
        String latitude = Double
                .toString(((double) loc.getLatitudeE6()) / 1000000);
        Toast toast = Toast.makeText(getApplicationContext(), "Longitude: "
                + longitude + " Latitude: " + latitude, Toast.LENGTH_SHORT);
        toast.show();

所以从这里怎么我会查询到从OSM获得城市名database..please帮助我。
我怎么能转化为人类可理解的形式这一点。这里是我的code,我现在用的。<一个href=\"http://stackoverflow.com/questions/19464694/how-to-get-the-place-name-by-latitude-and-longitude-using-openstreetmap-in-andro?noredirect=1#comment28903911_19464694\">link

推荐答案

试试这个code获取地址。

Try this code for getting address.

Geocoder geocoder;
List<Address> addresses;
geocoder = new Geocoder(this, Locale.getDefault());
addresses = geocoder.getFromLocation(latitude, longitude, 1);

String address = addresses.get(0).getAddressLine(0);
String city = addresses.get(0).getAddressLine(1);
String country = addresses.get(0).getAddressLine(2);

有关openstreammap

for openstreammap

    final String requestString = "http://nominatim.openstreetmap.org/reverse?format=json&lat=" +
            Double.toString(lat) + "&lon=" + Double.toString(lon) + "&zoom=18&addressdetails=1";

RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, URL.encode(requestString));
try {
    @SuppressWarnings("unused")
    Request request = builder.sendRequest(null, new RequestCallback() {
        @Override
        public void onResponseReceived(Request request, Response response) {
            if (response.getStatusCode() == 200) {
                String city = "";
                try {
                    JSONValue json = JSONParser.parseStrict(response);
                    JSONObject address = json.isObject().get("address").isObject();
                    final String quotes = "^\"|\"$";

                    if (address.get("city") != null) {
                        city = address.get("city").toString().replaceAll(quotes, "");
                    } else if (address.get("village") != null) {
                        city = address.get("village").toString().replaceAll(quotes, "");
                    }
                } catch (Exception e) {
                }
            }
        }
    });
} catch (Exception e) {
}

这篇关于如何在Android中使用OpenStreetMap的获取经度和纬度的地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 16:35