[英]I am using google map nearby places API in android. My code only shows the near by places
But i can not select each of them separately. 但是我不能分别选择它们中的每一个。
How can I select each of them separately by touching their marker and get their details. 如何触摸他们的标记分别选择他们并获取他们的详细信息。 A in this function below a json
array
is used of 0-19(20) elements. json
array
下的此函数中的A使用0-19(20)个元素。
I dont know how to use them to select each marker separately. 我不知道如何使用它们分别选择每个标记。
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());
}
}
implement GoogleMap.OnMarkerClickListener
and Override onMarkerClick
to detect click on marker 实现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.