簡體   English   中英

我在使用google map附近的地方API。 我的代碼僅顯示附近的地點

[英]I am using google map nearby places API in android. My code only shows the near by places

但是我不能分別選擇它們中的每一個。
如何觸摸他們的標記分別選擇他們並獲取他們的詳細信息。 json array下的此函數中的A使用0-19(20)個元素。

我不知道如何使用它們分別選擇每個標記。

private void parseLocationResult(final JSONObject result) {


    String id, place_id, placeName = null, reference, icon, vicinity = null;
    JSONArray rev;
    double latitude;
    double longitude;

    try {
        final JSONArray jsonArray = result.getJSONArray(RESULTS);//JavaScript Object Notation

        if (result.getString(STATUS).equalsIgnoreCase(OK)) {

            mMap.clear();

            for (int i = 0; i < jsonArray.length(); i++) {
                final JSONObject place = jsonArray.getJSONObject(i);

                id = place.getString(SUPERMARKET_ID);
                place_id = place.getString(PLACE_ID);
                if (!place.isNull(NAME)) {
                    placeName = place.getString(NAME);
                }
                if (!place.isNull(VICINITY)) {
                    vicinity = place.getString(VICINITY);
                }
                latitude = place.getJSONObject(GEOMETRY).getJSONObject(LOCATION)
                        .getDouble(LATITUDE);
                longitude = place.getJSONObject(GEOMETRY).getJSONObject(LOCATION)
                        .getDouble(LONGITUDE);
                reference = place.getString(REFERENCE);
                icon = place.getString(ICON);


                MarkerOptions markerOptions = new MarkerOptions();
                final LatLng latLng = new LatLng(latitude, longitude);
                markerOptions
                        .icon(BitmapDescriptorFactory.fromResource(R.drawable.bluemarker))
                        .position(latLng);
                markerOptions.title(placeName + " : " + vicinity);


                mMap.addMarker(markerOptions);



            }

            Toast.makeText(getBaseContext(), jsonArray.length() + " found!",
                    Toast.LENGTH_LONG).show();
        } else if (result.getString(STATUS).equalsIgnoreCase(ZERO_RESULTS)) {
            Toast.makeText(getBaseContext(), "Not found in 5KM radius!!!",
                    Toast.LENGTH_LONG).show();
        }

    } catch (JSONException e) {

        e.printStackTrace();
        Log.e(TAG, "parseLocationResult: Error=" + e.getMessage());
    }
}

實現GoogleMap.OnMarkerClickListener和Override onMarkerClick來檢測點擊標記

@Override
public boolean onMarkerClick(Marker marker) {

    // on marker clicked

    if (marker.equals(this.marker)) {
         // on specific marker clicked
    }
    return false;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM