• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Need help with a loop and drawing image on google maps

zukeru

Lurker
Oct 9, 2013
2
0
Below is a section of my code that handles the return of my json array. However I cant figure out how to check var id which is the users id to the users friends list and only display those values. I'm not even sure you can compare a string to array like this... Also can you help me with a link to somewhere that shows how to draw an image on google maps.
if (entity != null) { InputStream instream = entity.getContent(); String result= convertStreamToString2(instream); googleMap.clear(); JSONArray arr = new JSONArray(result); for (int i = 0; i < arr.length(); i++) { JSONObject jObj = arr.getJSONObject(i); String usernamei = jObj.getString("username"); String speedi = jObj.getString("speed"); String altitudei = jObj.getString("altitude"); String lats = jObj.getString("lat"); String lngs = jObj.getString("lng"); double latin = Double.parseDouble(lats); double lngin = Double.parseDouble(lngs); LatLng latLng = new LatLng(latin, lngin); double stlat = Double.parseDouble(lat); double stlng = Double.parseDouble(lng); Location locationA = new Location("point A"); locationA.setLatitude(stlat); locationA.setLongitude(stlng); Location locationB = new Location("point B"); locationB.setLatitude(latin); locationB.setLongitude(lngin); double distance = locationA.distanceTo(locationB); double cdist = 0.000621371; double fdist = cdist / distance; googleMap.addMarker(new MarkerOptions().position(latLng).title(usernamei).snippet(" Speed: " + speedi + " Altitude: " + altitudei + " Distance: " + fdist +"miles").icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE))); if (id.equals(usernamei)){ String friends = jObj.getString("friends"); List<String> list = new ArrayList<String>(Arrays.asList(friends.split(","))); TextView ff = (TextView) findViewById(R.id.friends); ff.setText(friends); } final EditText friend = (EditText) findViewById(R.id.friends); String friends = friend.getText().toString(); List<String> list = new ArrayList<String>(Arrays.asList(friends.split(","))); if(usernamei.equals(friends)){ googleMap.addMarker(new MarkerOptions().position(latLng).title(usernamei).snippet(" Speed: " + speedi + " Altitude: " + altitudei + " Distance: " + fdist +"miles").icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE))); } } instream.close(); }
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones