Google Maps Block for Users

I want the google map in my application to always be user-friendly and move with them as their current location changes. (Think that the Pokemon goes as the map really moves with the user)

My current best implementation is simply updating the camera location with animation every time the location changes:

// update the location of the camera based on the new latlng, but keep the zoom, tilt and bearing the same CameraUpdate cameraUpdate = CameraUpdateFactory.newCameraPosition(new CameraPosition(latLng, googleMap.getCameraPosition().zoom, MAX_TILT, googleMap.getCameraPosition().bearing)); googleMap.animateCamera(cameraUpdate); googleMap.setLatLngBoundsForCameraTarget(toBounds(latLng, 300)); 

This, however, makes camera movement somewhat intermittent, and it lags behind the user's actual location marker, especially if the user is moving fast.

Is there a way to relate the movement of the Google Maps camera so that it exactly matches the user's movement?

+3
android google-maps
source share
1 answer

I don’t think the marker is actually on GoogleMap in the case of Pokemon Go. If you want to fix the image (or any view) in the center of the map ... Just make sure the image is in the center of the map in your XML file.

Like this:

 <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:src="@mipmap/ic_self_position"/> <fragment android:layout_width="match_parent" android:layout_height="match_parent" class="com.google.android.gms.maps.SupportMapFragment"/> </RelativeLayout> 

So now you have a marker in the center of the map. Good, but you are still not in sync with the user's position ... So allow this.

I am going to assume that you have no problem launching your card. So do it, I'll wait. Are you done? OK. Set of cards.

Just remember to turn off drag and drop on the map:

 @Override public void onMapReady(GoogleMap googleMap) { googleMap.getUiSettings().setScrollGesturesEnabled(false); ... } 

Let me get the user's location and move the map.

Using this link:

https://developer.android.com/training/location/receive-location-updates.html

But change the piece of code to this:

  public class MainActivity extends ActionBarActivity implements ConnectionCallbacks, OnConnectionFailedListener, LocationListener { ... @Override public void onLocationChanged(Location location) { mCurrentLocation = location; mLastUpdateTime = DateFormat.getTimeInstance().format(new Date()); moveUser(Location location); } private void moveUser(Location location) { LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude()); mGoogleMap.animateCamera(CameraUpdateFactory.newLatLng(latLng)); mCharacterImageView.animate(pretendThatYouAreMovingAnimation) [you can make a animation in the image of the user... like turn left/right of make walk movements] } } 

If you want to rotate your symbol in the direction of movement, you will need to compare the previous Latlng with the new one and rotate the image (or see ... or something else) to indicate the direction of movement.

If you need more information, maybe this repo can help you: CurrentCenterPositionMap

(The repo does not do what you want ... it uses only the same concept of my explanation.)

+3
source share

All Articles