0

I am an android beginner and can't find the answer anywhere.

I want to show the markers on the map that are 25 km from the center of the map. I can't find the way to find the location of the center of the map, then show the markers that are 25km from it.

The geopoints are on Parse.com in the Cars.class, in the row "location". So far, event the code to show the markers doesn't work, it gets the results:

{"objectId": "[...]","location": {"__type":"GeoPoint","latitude": [...],"longitude": [...] },"createdAt":"[...]","updatedAt": "[...]"}

It crashes and gives me the error:

com.parse.ParseObject cannot be cast to com.company.test.Cars.

Thanks for the help!

    ParseQuery<Cars> query = ParseQuery.getQuery("Cars");
    query.selectKeys(Collections.singletonList("location"));   
    query.findInBackground(new FindCallback<Cars>(){

        @Override
        public void done(List<Cars> list, ParseException e) {
            if (e != null) {
                return;
            }
            ParseGeoPoint geoPoint;
           for(int i =0;i<list.size();i++){
               geoPoint = list.get(i).getParseGeoPoint("location");
               mMap.addMarker(new MarkerOptions().position(new LatLng(geoPoint.getLatitude(), geoPoint.getLongitude())));
Smittey
  • 2,475
  • 10
  • 28
  • 35
kirobo
  • 3
  • 2

1 Answers1

0

Ok so there is two options to achieve what you try to do.

One is a bit complicated but very powerful: everything is described here

Btw after you apply this option, it will be:

ParseQuery<Cars> query = ParseQuery.getQuery(Cars.class);

The other would sound less complex to me:

  1. Create a Parse.Query<Parse.Object> to get Parse.Object instead of Cars.
  2. In the done method, iterate through all the result
  3. Create a constructor of Car which takes a Parse.Object as parameter
  4. Convert every Parse.Object from the results into a Car Object via the constructor you just created.

This second option is maybe a bit more complex but way more flexible.

Laurent Meyer
  • 2,766
  • 3
  • 33
  • 57
  • Thanks. I had to put ParseObject instead of Cars: ParseQuery query = ParseQuery.getQuery("Cars"); query.findInBackground(new FindCallback() { – kirobo Sep 06 '16 at 12:29