Skip to content

Instantly share code, notes, and snippets.

@edwardinubuntu
Created March 28, 2015 09:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edwardinubuntu/eed3956a938c91bd898d to your computer and use it in GitHub Desktop.
Save edwardinubuntu/eed3956a938c91bd898d to your computer and use it in GitHub Desktop.
Query on map ready
@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