Hi I have created a map as well as some markers which indicate places/locations on the map. Is there any possible way of creating an animation between those location? For instance drawing a polyline between 2 different locations and create an animation from a start point to an end point ? Is there any documentation for such a thing or any tutorials ? Many thanks.
Something like this:
https://www.youtube.com/watch?v=HPWYorS68WE
use this code and you can also follow this link
https://developers.google.com/maps/documentation/android/
Flat Markers
LatLng mapCenter = new LatLng(41.889, -87.622);
map.moveCamera(CameraUpdateFactory.newLatLngZoom(mapCenter, 13));
// Flat markers will rotate when the map is rotated,
// and change perspective when the map is tilted.
map.addMarker(new MarkerOptions()
.icon(BitmapDescriptorFactory.fromResource(R.drawable.direction_arrow))
.position(mapCenter)
.flat(true)
.rotation(245));
CameraPosition cameraPosition = CameraPosition.builder()
.target(mapCenter)
.zoom(13)
.bearing(90)
.build();
// Animate the change in camera view over 2 seconds
map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition),
2000, null);
}
Related
I would like create effect described in the title on my markers when they are added. I see for ios exists method marker.appearAnimation but nothing similar for android. Now I will just add a BitmapDescription to MarkerOptions
final Marker marker = mMap.addMarker(new MarkerOptions()
.position(pos)
.icon(getIconForCluster(new BitmapDescriptor(getObjectWrapped()))
);
any suggestions?
You can use the animateCamera() method from GoogleMaps object.
Example:
mGoogleMap.setOnMapLoadedCallback(()
-> mGoogleMap.animateCamera(CameraUpdateFactory
.newLatLngZoom(mMapBoundary.getCenter(), 17)));
with mMapBoundary is a LatLngBounds object. you can set the markers position here, and 17 is the zoom level.
I want a Map UI like above dotted circle route path .I searched a lot through web and stack overflow i cant find any source.
I tried
addCircle polyline but the circle is large when i zoom the camera to
an extend in google map
I don't know how google map implemented it either with marker or
polyline
Provided help is appreciated rather than downvotes!!
thanks :-)
You can use Stroke Patterns for polylines like this:
#Override
public void onMapReady(GoogleMap googleMap) {
List<LatLng> sourcePoints = new ArrayList<>();
sourcePoints.add(new LatLng(22.724526, 75.825979));
sourcePoints.add(new LatLng(22.720165, 75.905953));
sourcePoints.add(new LatLng(22.766649, 76.075773));
sourcePoints.add(new LatLng(22.862032, 76.098302));
PolylineOptions polyLineOptions = new PolylineOptions();
polyLineOptions.addAll(sourcePoints);
polyLineOptions.width(50f);
polyLineOptions.color(Color.rgb(0, 178, 255));
Polyline polyline = googleMap.addPolyline(polyLineOptions);
List<PatternItem> pattern = Arrays.<PatternItem>asList(new Dot(), new Gap(10f));
polyline.setPattern(pattern);
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(sourcePoints.get(2))
.zoom(14)
.build();
googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
}
to get result like that:
Unfortunately it's impossible to draw bigger circles under smaller to achieve "bordered" circles path because of nonlinear dependency between Dot() and Gap() sizes.
Or you can draw whatever you want on MapVew canvas via overriding dispatchDraw() of MapView like in this answer (it's about MapBox MapView, but approach is applicable for Google Maps MapView too).
I think its overkill, but you can use some of Google APIs from https://console.developers.google.com/apis/library
and get path and make from them set of LatLngs, then draw them on googleMap just like normal marker, but with small round circle as icon.
To be honest, I am not sure what you want to achieve, I think simpler idea is to use origin and destination and open it in GoogleMaps Android App - do not reinvent the wheel.
I have implemented google map into my app. I have added a custom marker at my current location.I want to move the marker as the user moves, along with the map. I want to implement the functionality as in google maps navigation. While googling i found the following links but did not get the result. so can any one help me out ?
I have added this in onLocationChanged()
LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
sourceLocation = latLng;
startPoint = new GeoPoint(latLng.latitude,latLng.longitude);
forNavigation = location;
// animation
mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
// Zoom in the Google Map
mMap.animateCamera(CameraUpdateFactory.zoomTo(15));
// mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(mPositionMarker.getPosition(), 15));
mMap.animateCamera(CameraUpdateFactory.newLatLng(new LatLng(location
.getLatitude(), location.getLongitude())));
These are the links which i found
Google map: moving marker and map together smoothly along with user?
How to smoothly keep moving current location marker in Google Maps v2 android
here is two solution you have.
Use onlocationtrue then it show you blue dot as your current location.
Use fused api for current location and create you marker in locationchanged.
for fused api you can check from here.
thanks
I've been trying to work out a method for my application to indicate when there are markers on the map that are outside of the current view/screen/bound/VisibleRegion.
For example, if there are current 5 markers on the map but the user is zoomed into a part of the map where they can't see any of the markers then I would like to be able to flag up to the user that there are markers on the map that they cannot see or something along those lines (it would be nice to be able to indicate in which direction the markers are from the current position).
I thought of using
LatLngBounds currentScreen = googleMap.getProjection()
.getVisibleRegion().latLngBounds;
but this would only be able to tell me which markers are in the current visibleRegion.
any help would be appriciated, thanks.
First, you should save all your markers somewhere. For example, in list
List<Marker> markers = new ArrayList<>();
Marker marker = mMap.addMarker(new MarkerOptions().position(new LatLng(55.123, 36.456)));
markers.add(marker);
After this you can check, are there markers outside your screen
LatLngBounds currentScreen = mMap.getProjection().getVisibleRegion().latLngBounds;
for(Marker marker : markers) {
if(currentScreen.contains(marker.getPosition())) {
// marker inside visible region
} else {
// marker outside visible region
}
}
My App displays the driven route of the user. After a few seconds, the map stops loading new content and looks like this:
My Code:
XML
<fragment
xmlns:android="http://schemas.android.com/apk/res/android"
class="com.google.android.gms.maps.SupportMapFragment"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
map:cameraZoom="19"
android:layout_below="#+id/tracking_maps_colorgradient">
</fragment>
Java:
float zoom = 18;//googleMap.getCameraPosition().zoom;
LatLng latLng = new LatLng(lastLatitude, lastLongitude);
locations.add(latLng);
CameraPosition pos = new CameraPosition.Builder()
.target(latLng)
.bearing(bearing)
.zoom(zoom)
.tilt(googleMap.getCameraPosition().tilt)
.build();
googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(pos));
Polyline p = googleMap.addPolyline(new PolylineOptions()
.add(latLng)
.width(15)
.color(Color.RED)
.geodesic(true));
p.setPoints(locations);
Is there a way to invalidate the Map?
Thanks for your help!
Ok, for this ones who have the same problem, heres the solution. The Problem is that the GoogleMap doenst refresh all the time, you have to change the camera position when the user out the boundaries.
LatLngBounds bounds = this.googleMap.getProjection().getVisibleRegion().latLngBounds;
if(!bounds.contains(new LatLng(gps.getLatitude(), gps.getLongitude()))) {
//Move the camera to the user's location if they are off-screen!
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(new LatLng(gps.getLatitude(), gps.getLongitude()))
.zoom(zoom) // Sets the zoom
.bearing(bearing)
.build(); // Creates a CameraPosition from the builder
googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
}
Use Thread.sleep(300); after updating the map with markers, overlays, etc. Google Maps uses its own internal threads and need time to apply changes. It is possible that the thread adding stuff to the map is blocking Google Map's thread. The sleep will give it some time to make the update.
I don't know there is until you have a problem. But I solved and I wanted to share with you.
You can use handler and Thread.sleep(600). If you use just handler, you take same issue. Thread.sleep function waited for update map and than go on your marker.