Android Google Maps API V2 Zoom to Current Location

Try this coding: LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Criteria criteria = new Criteria(); Location location = locationManager.getLastKnownLocation(locationManager.getBestProvider(criteria, false)); if (location != null) { map.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(), location.getLongitude()), 13)); CameraPosition cameraPosition = new CameraPosition.Builder() .target(new LatLng(location.getLatitude(), location.getLongitude())) // Sets the center of the map to location user .zoom(17) // Sets the zoom .bearing(90) // Sets the orientation … Read more

How to animate marker in android map api V2?

None of versions provided worked for me, so I’ve implemented my custom solution. It provides both – location and rotation animation. /** * Method to animate marker to destination location * @param destination destination location (must contain bearing attribute, to ensure * marker rotation will work correctly) * @param marker marker to be animated */ … Read more

Android: automatically choose debug/release Maps v2 api key?

Using build.gradle buildTypes { debug { buildConfigField(“String”, “map_api_key”, “\”your debug map api key here\””) } release { buildConfigField(“String”, “map_api_key”, “\”your release map api key here\””) } } I solved this issue using this steps: In Google Developer API Console Click on Create New Android key… In cmd.exe/Terminal: keytool -list -v -keystore mystore.keystore Password: android Now … Read more

Google Maps API v2 SupportMapFragment inside ScrollView – users cannot scroll the map vertically

Apply a transparent image over the mapview fragment. <RelativeLayout android:id=”@+id/map_layout” android:layout_width=”match_parent” android:layout_height=”300dp”> <fragment android:id=”@+id/mapview” android:layout_width=”match_parent” android:layout_height=”match_parent” android:layout_marginTop=”-100dp” android:layout_marginBottom=”-100dp” android:name=”com.google.android.gms.maps.MapFragment”/> <ImageView android:id=”@+id/transparent_image” android:layout_width=”match_parent” android:layout_height=”match_parent” android:src=”https://stackoverflow.com/questions/16974983/@color/transparent” /> </RelativeLayout> Then set requestDisallowInterceptTouchEvent(true) for the main ScrollView. When the user touches the transparent image and moves disable the touch on the transparent image for MotionEvent.ACTION_DOWN and MotionEvent.ACTION_MOVE so that … Read more

How to handle onTouch event for map in Google Map API v2?

Here is a possible workaround for determining drag start and drag end events: You have to extend SupportMapFragment or MapFragment. In onCreateView() you have to wrap your MapView in a customized FrameLayout (in example below it is the class TouchableWrapper), in which you intercepts touch events and recognizes whether the map is tapped or not. … Read more

limit scrolling and zooming Google Maps Android API v2

Constraining the camera has (finally!) been added as a feature as part of the release of Google Play Services 9.4 — you can call setLatLngBoundsForCameraTarget(LatLngBounds bounds) to set the allowed panning area. // Create a LatLngBounds that includes the city of Adelaide in Australia. final LatLngBounds ADELAIDE = new LatLngBounds( new LatLng(-35.0, 138.58), new LatLng(-34.9, … Read more

How to get current Location in GoogleMap using FusedLocationProviderClient

This is similar to my other answer here, updated to use the recently introduced FusedLocationProviderClient class. In order to use a FusedLocationProviderClient in conjunction with a Google Map: Wait until the Google Map is ready Request the Location permission at runtime if needed Request location updates once the permission is granted Update the Google Map … Read more

How do I draw a route, along an existing road, between two points?

Indeed, you can draw precise route in Google Maps Android API using results provided by Directions API web service. If you read the documentation for Directions API you will see that response contains information about route legs and steps. Each step has a field polyline that is described in the documentation as polyline contains a … Read more