如何将Wikimapia与Google Map集成

时间:2014-12-05 12:53:21

标签: android google-maps

我正在开发一个Android应用程序,我希望从wikimapia获取最近的地方,并希望在Google地图上使用PinMarker显示这些位置。

我还使用以下代码来获取最近的医院位置,它使用Wikimapia到最近的医院,但我无法将其与我的Google地图集成。

String urlString = "http://api.wikimapia.org/?key="+key+"
            &function=place.getnearest&lat="+lastLocation.getLatitude()+
            "&lon="+lastLocation.getLongitude()+"&format=json&pack=&language=en&
            count=50&category="+category;
    try {

        URL url = new URL(urlString);

        URLConnection conn = url.openConnection();
        conn.setDoOutput(true);
        OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
        wr.flush();

        reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        StringBuilder sb = new StringBuilder();
        String line = null;

        while ((line = reader.readLine()) != null) {
            // Append server response in string
            sb.append(line + "");
        }

        String content = sb.toString();

        Logs.v(getLocalClassName(),
                "Places API InBackgroung, Contect = " + content);

        try {
            jObject = new JSONObject(content);

        } catch (Exception e) {
            Logs.e("Exception", e.toString());
        }
    }

    JSONArray arrayOfPlaces = jObject.getJSONArray("places");

    for (int i = 0; i < arrayOfPlaces.length(); i++) {

        final MarkerOptions markerOptions = new MarkerOptions();

        JSONObject jPlace = arrayOfPlaces.getJSONObject(i);

        if (!jPlace.isNull("title")) {
            place = jPlace.getString("title");
        }
        if (!jPlace.isNull("urlhtml")) {
            icon = jPlace.getString("urlhtml");
        }
        if (!jPlace.isNull("distance")) {
            distance = jPlace.getString("distance");
        }                       

        latitude = jPlace.getJSONObject("location").getString("lon");
        longitude = jPlace.getJSONObject("location").getString("lat");

        double lat = Double.parseDouble(latitude);
        double lng = Double.parseDouble(longitude);
        LatLng latLng = new LatLng(lat, lng);
        markerOptions.position(latLng);
        markerOptions.title(place);
        markerOptions.icon(BitmapDescriptorFactory.fromResource(R.drawable.hospital_building));
//Every value is getting through parsing, but pin markers are not displaying on the maps
//Secondly what is .setSnippet here??
        mMap.addMarker(markerOptions).setSnippet("");

    }

0 个答案:

没有答案