Draw path traced by device using maps api v2 - android

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:

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.

Android google-maps v2 polyline wrong

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);

How to draw route with multiple via point on google map api android

I want to draw route on Google Map API in android studio from point A to point G, so I need to specified the B,C,D,E,and F via point between point A to G, but most of sample just explains about draw a via point, as example from point A to point C, then the via point is B. please help me.
regards
I believe you are looking for polylineOptions
PolylineOptions polylineOptions = new PolylineOptions();
// add the various point with
polylineOptions.add(latLng);
//adn add to google map using
googleMap.addPolyline(polylineOptions);
the link can help you other stuff you can do with polyline.

Draw path between two points on the map-google maps using Eclipse

I'm writing program in android google map v2 .
I created markers as ArrayList
Now, I want to find the street, between two points on the map how ???
Help me !!
Thanks
Use the Following Code:-
/************************** Drawing polyline if there are more than 1 latlngs **************/
if (arraylist_lat_lon.size() > 1) {
PolylineOptions polyline_options = new PolylineOptions()
.addAll(arraylist_lat_lon).color(Color.GREEN).width(2);
polyline = googleMap.addPolyline(polyline_options);
}
Note: arraylist_lat_lon : Array List where you are storing your LatLngs

Android draw polyline maps V2

I have a List with LatLng objects that form a route I want to draw on my map. I am using a SupportMapFragment and I call this method below on onActivityCreated. I have another method called from there that creates markers and that one is executed fine but my method below does not draw the polyline. I have searched for examples but could not find any that suit my needs. Can someone please point out what I'm doing wrong here?
private void drawRoute() {
List<LatLng> latLngs = CoordinateEntity.getRouteLatLngs();
PolylineOptions line = new PolylineOptions();
line.width(5);
line.color(Color.RED);
for (LatLng latLng : latLngs) {
line.add(latLng);
}
getMap().addPolyline(line);
}
I have looked at this and other similar examples and all follow this code pattern
mMap.addPolyline(new PolylineOptions()
.add(new LatLng(lats, lons), new LatLng(late,lone))
.width(5)
.color(color));
Is this the only way a Polyline can be added to the map?
Found my problem.
I had the play services jar added to my project and for some reason everything of the maps V2 api worked except drawing lines.
I then added the play services project as a dependency and after I did that everything worked.

Categories

Resources