Created
March 28, 2015 09:12
-
-
Save edwardinubuntu/eed3956a938c91bd898d to your computer and use it in GitHub Desktop.
Query on map ready
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public void onMapReady(final GoogleMap googleMap) { | |
ParseQuery<Photo> photoParseQuery = ParseQuery.getQuery(Photo.class); | |
photoParseQuery.setCachePolicy(ParseQuery.CachePolicy.CACHE_ELSE_NETWORK); | |
photoParseQuery.findInBackground(new FindCallback<Photo>() { | |
@Override | |
public void done(List<Photo> photos, ParseException e) { | |
if (e == null) { | |
photoList.clear(); | |
photoList.addAll(photos); | |
List<MarkerOptions> markerOptionsList = new ArrayList<MarkerOptions>(); | |
for (Photo eachPhoto : photos) { | |
if (eachPhoto.getLocation() != null) { | |
MarkerOptions markerOptions = new MarkerOptions() | |
.title(eachPhoto.getName()) | |
.position(new LatLng(eachPhoto.getLocation().getLatitude(), | |
eachPhoto.getLocation().getLongitude() | |
)); | |
markerOptionsList.add(markerOptions); | |
googleMap.addMarker(markerOptions); | |
} | |
} | |
//Calculate the markers to get their position | |
LatLngBounds.Builder builder = new LatLngBounds.Builder(); | |
for (MarkerOptions marker : markerOptionsList) { | |
builder.include(marker.getPosition()); | |
} | |
LatLngBounds bounds = builder.build(); | |
// Change the padding as per needed | |
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBounds(bounds, 0); | |
googleMap.moveCamera(cameraUpdate); | |
} | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment