在OnkeyMoved中旋转标记

时间:2018-06-11 09:30:56

标签: android rotation geolocation google-maps-markers geo

我尝试使用引用driverlocation为geoquery中可用的所有键放置标记。 所有标记都在onKeyEntered方法中按预期创建,并且每个标记的位置随onKeyMoved中的markerIt.setPosition()而变化。

但是我希望在调用onKeyMoved时旋转标记而不是设置位置。

public void loadAllAvailableDrivers(final LatLng location) {

    if (driverlocation != null) {
        final GeoFire gfGeofire = new GeoFire(driverlocation);
        final GeoQuery geoQuery = gfGeofire.queryAtLocation(new GeoLocation(location.latitude, location.longitude), distance);
        geoQuery.removeAllListeners();
        geoQuery.addGeoQueryEventListener(new GeoQueryEventListener() {
            @Override
            public void onKeyEntered(final String key, final GeoLocation location) {
                Log.d("loadall Onkey", key);


                FirebaseDatabase.getInstance().getReference(Common.DriversInfo).child(key)
                        .addListenerForSingleValueEvent(new ValueEventListener() {
                            @Override
                            public void onDataChange(DataSnapshot dataSnapshot) {

                                Log.d("loadall Infokey", key);

                                if (dataSnapshot.exists()) {

                                    rider = dataSnapshot.getValue(User.class);

                                    selectedDriverId = dataSnapshot.getKey();
                                    Map<String, Object> map = (Map<String, Object>) dataSnapshot.getValue();
                                    driverCarType = map.get("carType").toString();
                                    Log.d("loaddrivercar", driverCarType);

                                    if (Common.CarType != null && Common.CarType.equals(driverCarType)) {

                                        Marker mDriverMarker = mMap.addMarker(new MarkerOptions()
                                                .position(new LatLng(location.latitude, location.longitude))
                                                .title("Driver : " + rider.getName())
                                                .snippet("DriverId : " + selectedDriverId)
                                                .flat(true)
                                                .icon(BitmapDescriptorFactory.fromBitmap(icon)));


                                        markerList.add(mDriverMarker);

                                        Log.d("marker", String.valueOf(markerList));
                                        Log.d("marker tag", String.valueOf(mDriverMarker.getTag()));

                                    }

                                    Log.d("latlng driver", location.latitude + "," + location.longitude);
                                }

                            }

                            @Override
                            public void onCancelled(DatabaseError databaseError) {

                            }
                        });


            }

            @Override
            public void onKeyExited(String key) {

                for (Marker markerIt : markerList) {
                    if (markerIt.getSnippet().replace("DriverId : ", "").equals(key)){
                        markerIt.remove();
                        markerList.remove(markerIt);
                        return;
                    }

                }

            }

            @Override
            public void onKeyMoved(String key, GeoLocation location) {

                pre = current;
                if(pre == null){
                    pre = new LatLng(0.00,0.00);
                }
                current = new LatLng(location.latitude, location.longitude);

                for (Marker markerIt : markerList) {
                    if (markerIt.getSnippet().replace("DriverId : ", "").equals(key)) {

                        markerIt.setPosition(new LatLng(location.latitude,location.longitude));


            public void onGeoQueryReady() {
                if (distance <= LIMIT) {
                    distance++;
                    loadAllAvailableDrivers(location);
                }

            }

            @Override
            public void onGeoQueryError(DatabaseError error) {

            }
        });

    }
}

我想让标记旋转,如图所示

markerImage

0 个答案:

没有答案