I have a method "onPostExecute()" that shows Markers parsed from JSON and it worked fine. Now I want to show the nearest Marker from my current position. What should I do?
Here is the code below.
public void onPostExecute(String json) {
try {
// De-serialize the JSON string into an array of branch objects
JSONArray jsonArray = new JSONArray(json);
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObj = jsonArray.getJSONObject(i);
LatLng latLng = new LatLng(jsonObj.getDouble("latitude"),
jsonObj.getDouble("longitude"));
// Create a marker for each branch in the JSON data.
map.addMarker(new MarkerOptions()
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED))
.title(jsonObj.getString("name"))
// .snippet(Integer.toString(jsonObj.getInt("snippet")))
.snippet(jsonObj.getString("snippet"))
.position(latLng));
}
} catch (JSONException e) {
Log.e(LOG_TAG, "Error processing JSON", e);
}
}