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

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

Related

How Can I Draw Colorful Path in Google Maps?

I work for a project about Google Maps and Traffic.
I want to draw route but ı want it to be colorful for my situation.
How can I draw a route colorful same line ?
Can anyone help me ?
Thanks a lot :)
If you are using PolylineOptions class to draw line then the following will help you:
PolylineOptions lineOptions = new PolylineOptions();
/* code for adding points ... */
lineOptions.color(Color.RED);
// You can also use following
// lineOptions.color(Color.parseColor("#ff00ff"));

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.

How to clear route from google map android v2 using PolylineOptions and draw a new one again?

I am getting the latitude and longitude on every onLocationChange and make a route like this:
public void onLocationChanged(Location location) {
PolylineOptions rectLine2;
rectLine2.add(new LatLng(lat, lon));
mGoogleMap.addPolyline(rectLine2);
}
Now I want to clear this route on one click, and again when I move, a fresh route should draw,
but in my case, old route doesn't clear.
I did the following but not working:
mGoogleMap.clear();// It clear's the map, but when I again draw the old route again comes.
Also
Polyline polyline;
polyline = mGoogleMap.addPolyline(rectLine2);
polyline.reomve()// This also didn't work.
Is there any other solution to clear the map?
Thanks In Advance!
mGoogleMap.clear()
is used to clear the whole map so that you can redraw the polylines...
else you need to assign a variable to polyline and you can remove it...
PolylineOptions rectLine2;
rectLine2.add(new LatLng(lat, lon));
Polyline polyline = mGoogleMap.addPolyline(rectLine2);
polyline.remove();
These are the ways... Why do you need any other solution to clear..?
If you have number of polylines then just create an array and remove all polylines once you need to clear
Hmm, that's intresting, try this way, it's working for me:
private void clearPath() {
if (polyline != null)
polyline.remove();
polyline = null;
}
mGoogleMap.clear() is the best way to clean the map. It removes all markers, polylines, polygons, overlays, etc from the map. see this http://developer.android.com/reference/com/google/android/gms/maps/GoogleMap.html#clear()
So the problem is not in that. You are doing something wrong in reDrawing the new path. I think you have not given all code in your onLocationChanged function. And if this is your final code than this should not work as you are only adding one point in the PolylineOptions.
Please check this How to draw interactive Polyline on route google maps v2 android
Hope it will help
Try clearing your rectLine2 variable also. May be it's having all old latlangs. So on your click.
rectLine2 = new PolylineOptions();
Use map.clear() method to clear all map (polylines, markers, etc) or save all polylines somewhere and them remove them to save everything else
for(Polyline polyline : polylineList) {
polyline.remove();
}

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:

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