Android google-maps v2 polyline wrong - android

I am recording coordinated inside onLocationChanged() and drawing polylines between each to create the route taken by the user. But sometimes the polylines extend to infinity and off the screen as seen here. They disappear at certain zoom levels but reappear when you zoom back in. Below is the code used:
map.moveCamera(CameraUpdateFactory.newLatLng(driver));
routePoints.add(driver); // driver is location object
PolylineOptions polylineOptions = new PolylineOptions();
polylineOptions.color(Color.RED);
polylineOptions.addAll(routePoints);
map.addPolyline(polylineOptions);

Related

Dotted circle route path like google map

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.

Move the marker along the with map as the user moves

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

Snapshot google maps api v2 between two points

i'm doing an app in android studio and what i'm trying to do is a route tracking app, the user touch a play button and he can see in the map a marker with his route being drawn by polylines.
I did that already but i want your help because when the user touch the stop button i want to take a Snapshot of the complete route (including the start point and the end point) and i don't know how to do that, because if the route is long and the zoom is close to the map then the starting point isn't going to show...
I hope you understand and could help me! :)
Sorry for my English, I use this example in my code to zoom all the markers, its simple i use a cycle for add the LatLng and zoom all.. with CameraUpdateFactory.newLatLngBounds(bounds_latandlog,padding);, and you take the Snapshot...
LatLngBounds.Builder builder = new LatLngBounds.Builder();
///this is an example
LatLng latLng;// create var LatLng
for(int i=0;i<=10;i++)// you will do a type of cycle, tu add lat and long
{
latLng = new LatLng(lat, lon);// in this line put you lat and long
builder.include(latLng); //add latlng to builder
}
//create a lat long bounds
LatLngBounds bounds = builder.build();
//create a padding of the points and the camera of the map
int padding = 0; // offset from edges of the map in pixels
CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, padding);
//finally move the camera, to zoom all the polylines
/// move the camera
googleMap.moveCamera(cu);
//or animate the camera...
googleMap.animateCamera(cu);
This is the link, for more information
Android map v2 zoom to show all the markers
if you see some error, or you have a better syntaxis, please explane me, I want to learn it.

Android Google Maps V2 - Indicate if there are markers outside of the current VisibleRegion on screen

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
}
}

Draw path traced by device using maps api v2

I am developing an android application to trace the device movement.I am able to get the current location but how can i draw the route with set of points collected during trip
Define List for all points.
List< LatLng> points = new List< LatLng>();
//Add all points in list
points.add(new LatLng(lat1,lng1)); // POINT1
points.add(new LatLng(lat2,lng2)); // POINT2 and so on.
// then define PolylineOptions
PolylineOptions polylineOptions = new PolylineOptions();
polylineOptions.addAll(points);
Polyline route = googleMap.addPolyline(polylineOptions);
// for marker use MarkerOptions
Use something more reliable than drawing a route: Markers.
Check the google maps Sample application from the Android SDK, and take a look on the MarkerDemoActivity.java class.
Open eclipse:
New Project->Android Sample Project->[YOUR_BUILD_TARGET]->maps [Google Play Service]
This will give you a good idea about what you're trying to search for.
Here's an example of what you'll get:

Categories

Resources