OnMarkerClick startactivity(intent),从Parse

时间:2016-04-11 14:58:40

标签: android google-maps parse-platform

我想从Parse Cloud加载图片。我已经使用从Parse Cloud加载的照片创建了自定义标记。照片标记图标工作得很好。但是当我点击标记图标时,我想启动并传递意图。但无论我选择在意图中选择哪个选项,它只能查看我的Parse类中的第一个对象。查看地图here的屏幕截图。当我点击任何图像时,相同的图像即第一个对象在类中加载。

super.onCreate(savedInstanceState);             的setContentView(R.layout.map_fragment);             mapFragment =(SupportMapFragment)getSupportFragmentManager()。findFragmentById(R.id.map);

        mHandler.postDelayed(new Runnable() {
            public void run() {
                onResume();
            }
        }, 3000);
        mylocation = MainActivity.mlastlocation;
        // Gets to GoogleMap from the MapView and does initialization stuff
        mapFragment.getMap().setMyLocationEnabled(true);
        // Enable the current location "blue dot"
        mapFragment.getMap().setOnCameraChangeListener(new GoogleMap.OnCameraChangeListener() {
                  public void onCameraChange(CameraPosition position) {

        if (mylocation == null) {
            Toast.makeText(MapFeedsFragment.this, "null", Toast.LENGTH_SHORT).show();
        }
        if (mylocation != null)
            Toast.makeText(MapFeedsFragment.this, "not null", Toast.LENGTH_SHORT).show();
                      ParseMap aroundposts = new ParseMap();
        doMapQuery();
        }
            });
    }

    private ParseGeoPoint geoPointFromLocation(Location location) {
        latitude = location.getLatitude();
        longitude = location.getLongitude();
        ParseGeoPoint myloc = new ParseGeoPoint(latitude, longitude);
        return myloc;
    }



    private void doMapQuery() {
        final int myUpdateNumber = ++mostRecentMapUpdate;
        //Location myLoc = (currentLocation == null) ? lastLocation : currentLocation;
        // If location info isn't available, clean up any existing markers
        if (mylocation == null) {
            cleanUpMarkers(new HashSet<String>());
            return;
        }
        final ParseGeoPoint myPoint = geoPointFromLocation(mylocation);
        // Create the map Parse query
        ParseQuery<ParseMap> mapQuery = ParseMap.getQuery();
        // Set up additional query filters
        //mapQuery.whereWithinKilometers("location", myPoint, MAX_POST_SEARCH_DISTANCE);
        mapQuery.include("user");
        mapQuery.orderByDescending("createdAt");
        //mapQuery.setLimit(MAX_POST_SEARCH_RESULTS);
        // Kick off the query in the background
        mapQuery.findInBackground(new FindCallback<ParseMap>() {
            @Override
            public void done(List<ParseMap> objects, ParseException e) {
                if (e != null) {
                    //if (Application.APPDEBUG) {
                    //  Log.d(Application.APPTAG, "An error occurred while querying for map posts.", e);
                    //}
                    return;
                }
        /*
         * Make sure we're processing results from
         * the most recent update, in case there
         * may be more than one in progress.
         */
                if (myUpdateNumber != mostRecentMapUpdate) {
                    return;
                }
                // Posts to show on the map
                Set<String> toKeep = new HashSet<String>();
                // Loop through the results of the search
                for (final ParseMap post : objects) {
                    // Add this post to the list of map pins to keep
                    toKeep.add(post.getObjectId());
                    // Check for an existing marker for this post
                    Marker oldMarker = mapMarkers.get(post.getObjectId());
                    // Set up the map marker's location
                    String uri = post.getPhotoThumb().getUrl();
                   // final MarkerOptions finalMarkerOpts = markerOpts;
                    Picasso.with(MapFeedsFragment.this)
                            .load(uri)
                            .resize(100,100)
                            .centerCrop()
                            .into(new Target() {
                                @Override
                                public void onBitmapLoaded(final Bitmap bitmap, Picasso.LoadedFrom from) {
            /* Save the bitmap or do something with it here */

                                    final MarkerOptions markerOpts =
                                            new MarkerOptions().position(new LatLng(post.getLocation().getLatitude(), post
                                                    .getLocation().getLongitude())).icon(BitmapDescriptorFactory.fromBitmap(bitmap)).title(post.getUser());
                                    // Add a new marker
                                    Marker marker = mapFragment.getMap().addMarker(markerOpts);
                                    mapMarkers.put(post.getObjectId(), marker);
                                    mapMarkers.put(post.getVideo().getUrl(),marker);
                                    mapMarkers.put(post.getUserId(),marker);

                                    mapMarkers.put(String.valueOf(post.getViews()),marker);

                                }

                                @Override
                                public void onBitmapFailed(Drawable errorDrawable) {

                                }

                                @Override
                                public void onPrepareLoad(Drawable placeHolderDrawable) {

                                }
                            });



                        mapFragment.getMap().setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {

                            @Override
                        public boolean onMarkerClick(Marker marker) {
                            Intent intent = new Intent (MapFeeds.this,PhotoView.class);
                                intent.putExtra("objectId",post.getObjectId());
                                intent.putExtra("photo", String.valueOf(post.getPhoto().getUrl()));
                            intent.putExtra("userId",post.getUserId());
                            intent.putExtra("objectId",post.getObjectId());

                            startActivity(intent);
                            return false;
                        }
                    });
                }
            }
        });
    }

0 个答案:

没有答案