You are on page 1of 17

Android Google Maps Tutorial Part 7, Drawing A Path or Line Between Two Locat...

Pgina 1 de 17

Mir

Mir Nauman Tahir. Development, Configurations, Tutorials and bla bla


bla ....

Android Google Maps Tutorial Part 7, Drawing A Path


or Line Between Two Locations
April 26, 2012 in Android Google Maps API Ver 1.0

I have been trying this for a month and a lot of my readers asked to write a tutorial that makes it easy to draw a
line on Google Maps for Android between two locations. I have gone through a lot of material. Most of the
articles on this exact issue are not exactly addressing this specific issue. So their code is way too complex for
this simple task. I have tried to make this as simple as possible.

Assumption About The Reader:

At this point I assume that reader of this article have already configured everything and Google Maps are
displayed in their emulator properly. For those who dont have Google Maps properly displayed in their
emulator, they can read my earlier articles. Links provided at the end of this article.

Objective:

Draw a line that between two points on Google Maps lets say City A and City B. Repeat the process to
draw a line between City B and City C.

What we need:

Coordinates of 3 cities or any 3 locations that we want to connect.

1. Abbottabad : 34159000,73220000
2. Islamabad : 33695043,73050000
3. Rawalpindi : 33615043, 73050000

I have taken relative coordinates of 3 Pakistani cities starting from Abbottabad (where my family lives), moving
to Islamabad (Capital of Pakistan). From Islamabad moving to Rawalpindi.

Coding (the part everyones been waiting for):

Create an overlay class lets say by the name of MyOverlay inside our main activity class named
GoogleMapsDrawPath that extends MapActivity

1 class MyOverlay extends Overlay{


2
3 public MyOverlay(){
4
5 }
6
7 public void draw(Canvas canvas, MapView mapv, boolean shadow){
8 super.draw(canvas, mapv, shadow);
9
10 //Configuring the paint brush
11

http://mirnauman.wordpress.com/2012/04/26/android-google-maps-tutorial-part-7-dra... 08/10/2013
Android Google Maps Tutorial Part 7, Drawing A Path or Line Between Two Locat... Pgina 2 de 17

12 Paint mPaint = new Paint();


13 mPaint.setDither(true);
14 mPaint.setColor(Color.RED);
15 mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
16 mPaint.setStrokeJoin(Paint.Join.ROUND);
17 mPaint.setStrokeCap(Paint.Cap.ROUND);
18 mPaint.setStrokeWidth(4);
19
20 GeoPoint gP1 = new GeoPoint(34159000,73220000);//starting point Abbottabad
21 GeoPoint gP2 = new GeoPoint(33695043,73050000);//End point Islamabad
22
23 GeoPoint gP4 = new GeoPoint(33695043, 73050000);//Start point Islamabad
24 GeoPoint gP3 = new GeoPoint(33615043, 73050000);//End Point Rawalpindi
25
26 Point p1 = new Point();
27 Point p2 = new Point();
28 Path path1 = new Path();
29
30 Point p3 = new Point();
31 Point p4 = new Point();
32 Path path2 = new Path();
33 projection.toPixels(gP2, p3);
34 projection.toPixels(gP1, p4);
35
36 path1.moveTo(p4.x, p4.y);//Moving to Abbottabad location
37 path1.lineTo(p3.x,p3.y);//Path till Islamabad
38
39 projection.toPixels(gP3, p1);
40 projection.toPixels(gP4, p2);
41
42 path2.moveTo(p2.x, p2.y);//Moving to Islamabad location
43 path2.lineTo(p1.x,p1.y);//Path to Rawalpindi
44
45 canvas.drawPath(path1, mPaint);//Actually drawing the path from Abbottabad to Islamabad
46 canvas.drawPath(path2, mPaint);//Actually drawing the path from Islamabad to Rawalpindi
47
48 }
49
50 }

Explanation:

The code is pretty self explanatory as I have commented the parts that required explanation. First we configure
the paint brush. To draw a line between two points we need to have coordinates of at least two locations but as
I am connecting 3 locations, I have taken 4 GeoPoints , repeating the coordinates of Islamabad. I have done this
to demonstrate that each time we draw a line we will need two points. After that I have created 4 Points and 2
Paths. Than setting the Projection. In simple words associating the GeoPoints to Points. After this setting the
Paths like moving it to a starting location and defining the end point of the Path. Lastly call the canvas.drawPath
(path1, mPaint) method providing it the path and the brush to actually draw the line on the map.

Configuring the Main Activity Class:

Add the following code in the onCreate method of GoogleMapsDrawPath class.

1 mapView = (MapView) findViewById(R.id.mapview1);//Creating an instance of MapView


2 mapView.setBuiltInZoomControls(true);//Enabling the builtin Zoom Controls
3
4 gP = new GeoPoint(33695043, 73000000);//Creating a GeoPoint
5
6 mc = mapView.getController();
7 mc.setCenter(gP);
8 mc.setZoom(9);//Initializing the MapController and setting the map to center at the
9 //defined GeoPoint
10
11 mapOverlays = mapView.getOverlays();
12 projection = mapView.getProjection();
13
14 myoverlay = new MyOverlay();

http://mirnauman.wordpress.com/2012/04/26/android-google-maps-tutorial-part-7-dra... 08/10/2013
Android Google Maps Tutorial Part 7, Drawing A Path or Line Between Two Locat... Pgina 3 de 17

Explanation:

Create instance of the mapView, enable the built-in zoom controls. Create GeoPoints and move the map to
center at the created GeoPoint. Lastly add overlays from the myOverlay class to the map.

Path starting from Abbottabad moving towards


Islamabad

Path Reaching Islamabad and than the second Path


Starting from Islamabad to Rawalpindi

http://mirnauman.wordpress.com/2012/04/26/android-google-maps-tutorial-part-7-dra... 08/10/2013
Android Google Maps Tutorial Part 7, Drawing A Path or Line Between Two Locat... Pgina 4 de 17

Complete path starting from Abbottabad to


Rawalpindi. It looks like one single line but actually it
consists of two line. The second one starting from the
point where the first one is ending.

Some Extras that need explanation:

I feel the need of explaining a few more things that even if we dont understand the code will work. But the
readers have the right to know why a certain method, object, class etc is used.

GeoPoint :An immutable class representing a pair of latitude and longitude, stored as integer numbers of
microdegrees
Projection :A Projection serves to translate between the coordinate system of x/y on-screen pixel coordinates
and that of latitude/longitude points on the surface of the earth.
Point :Converts the given GeoPoint to onscreen pixel coordinates, relative to the top-left of
the MapView that provided this Projection

Complete Code for GoogleMapsDrawPath Application:

1 package com.android.googlemapsdrawpath;
2
3 import java.util.List;
4
5 import com.google.android.maps.GeoPoint;
6 import com.google.android.maps.MapActivity;
7 import com.google.android.maps.MapController;
8 import com.google.android.maps.MapView;
9 import com.google.android.maps.Overlay;
10 import com.google.android.maps.Projection;
11
12 import android.graphics.Canvas;
13 import android.graphics.Color;
14 import android.graphics.Paint;
15 import android.graphics.Path;
16 import android.graphics.Point;
17 import android.os.Bundle;
18
19 public class GoogleMapsDrawPath extends MapActivity {
20 /** Called when the activity is first created. */
21 private List mapOverlays;

http://mirnauman.wordpress.com/2012/04/26/android-google-maps-tutorial-part-7-dra... 08/10/2013
Android Google Maps Tutorial Part 7, Drawing A Path or Line Between Two Locat... Pgina 5 de 17

23 private MapController mc;


24 private MapView mapView;
25 private GeoPoint gP;
26 //private GeoPoint gP2;
27 private MyOverlay myoverlay;
28
29 @Override
30 public void onCreate(Bundle savedInstanceState) {
31 super.onCreate(savedInstanceState);
32 setContentView(R.layout.main);
33
34 mapView = (MapView) findViewById(R.id.mapview1);//Creating an instance of MapView
35 mapView.setBuiltInZoomControls(true);//Enabling the builtin Zoom Controls
36
37 gP = new GeoPoint(33695043, 73000000);//Creating a GeoPoint
38
39 mc = mapView.getController();
40 mc.setCenter(gP);
41 mc.setZoom(9);//Initializing the MapController and setting the map to center at the
42 //defined GeoPoint
43
44 mapOverlays = mapView.getOverlays();
45 projection = mapView.getProjection();
46
47 myoverlay = new MyOverlay();
48 mapOverlays.add(myoverlay);
49
50 }
51
52 @Override
53 protected boolean isRouteDisplayed() {
54 // TODO Autogenerated method stub
55 return false;
56 }
57
58 class MyOverlay extends Overlay{
59
60 public MyOverlay(){
61
62 }
63
64 public void draw(Canvas canvas, MapView mapv, boolean shadow){
65 super.draw(canvas, mapv, shadow);
66 //Configuring the paint brush
67 Paint mPaint = new Paint();
68 mPaint.setDither(true);
69 mPaint.setColor(Color.RED);
70 mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
71 mPaint.setStrokeJoin(Paint.Join.ROUND);
72 mPaint.setStrokeCap(Paint.Cap.ROUND);
73 mPaint.setStrokeWidth(4);
74
75
76 GeoPoint gP1 = new GeoPoint(34159000,73220000);//starting point Abbottabad
77 GeoPoint gP2 = new GeoPoint(33695043,73050000);//End point Islamabad
78
79 GeoPoint gP4 = new GeoPoint(33695043, 73050000);//Start point Islamabad
80 GeoPoint gP3 = new GeoPoint(33615043, 73050000);//End Point Rawalpindi
81
82 Point p1 = new Point();
83 Point p2 = new Point();
84 Path path1 = new Path();
85
86 Point p3 = new Point();
87 Point p4 = new Point();
88 Path path2 = new Path();
89 projection.toPixels(gP2, p3);
90 projection.toPixels(gP1, p4);
91
92 path1.moveTo(p4.x, p4.y);//Moving to Abbottabad location
93 path1.lineTo(p3.x,p3.y);//Path till Islamabad
94
95 projection.toPixels(gP3, p1);
96 projection.toPixels(gP4, p2);

http://mirnauman.wordpress.com/2012/04/26/android-google-maps-tutorial-part-7-dra... 08/10/2013
Android Google Maps Tutorial Part 7, Drawing A Path or Line Between Two Locat... Pgina 6 de 17

97
98 path2.moveTo(p2.x, p2.y);//Moving to Islamabad location
99 path2.lineTo(p1.x,p1.y);//Path to Rawalpindi
100
101 canvas.drawPath(path1, mPaint);//Actually drawing the path from Abbottabad to Islamabad
102 canvas.drawPath(path2, mPaint);//Actually drawing the path from Islamabad to Rawalpindi
103
104 }
105
106 }
107 }

Related articles

Android Google Maps Tutorial Part 1. Basic Development. (mirnauman.wordpress.com)


Android Google Maps Tutorial Part 2. Using GPS in Android and Animating Google Maps to the Current GPS
location. (mirnauman.wordpress.com)
Android Google Maps Tutorial Part 3. Adding An Image to GoogleMaps Using Map Overlays.
(mirnauman.wordpress.com)
Android Google Maps Tutorial Part 5, Adding Multiple Images To Google Maps Using ItemizedOverlay.
(mirnauman.wordpress.com)
Android Google Maps Tutorial Part 6, Getting The Location That Is Touched. (mirnauman.wordpress.com)
About these ads

Share this:

Like this: Loading...

66 comments
Comments feed for this article

April 27, 2012 at 4:34 am [...] Android Google Maps Tutorial Part 7, Drawing A
Android Google Maps Tutorial Part Path or Line Between Two Locations
3. Adding An Image to GoogleMaps (mirnauman.wordpress.com) [...]
Using Map Overlays. Mir Reply

April 27, 2012 at 4:37 am

http://mirnauman.wordpress.com/2012/04/26/android-google-maps-tutorial-part-7-dra... 08/10/2013
Android Google Maps Tutorial Part 7, Drawing A Path or Line Between Two Locat... Pgina 7 de 17

Android Google Maps Tutorial Part [...] Android Google Maps Tutorial Part 7, Drawing A
4, Adding Menu & Some Additional Path or Line Between Two Locations
Functionality Like Zooming, (mirnauman.wordpress.com) Share
Changing Map View, Animating To this:TwitterLinkedInFacebookEmailPrintLike this:LikeBe
GPS Current Location Using Menu the first to like this post. Categories [...]
Button. Mir Reply

May 9, 2012 at 3:57 am Reblogged this on Mir.


Mir
Reply

May 13, 2012 at 8:37 am Hi Mir i have a question can you help
andrias me with this i want when i touch one of
the stars in the map to open an information
viewer for example information
about Islamabad

Reply

May 17, 2012 at 9:45 am Hi, I have one doubt did you check the
satyanarayana same code work for from France to
Abbottabad.

Reply

May 17, 2012 at 10:46 am ideally it should work, coz the code
Mir needs a starting lat, long and and ending
lat, long. now it depends on u which ever start
end locations u select. but if u have tried it and its not working than u should
zoom in or out a lil. thay may solve the issue.

Reply

May 21, 2012 at 8:07 am Great tutorial .. you are talented in


Ahmed making the tutorial clear and easy to
follow.
I can see that your tutorial explaining how to draw a path between two
Geopoints, do you have any idea of how to implement a complete route
between two locations, i.e not only the direct path?
thanks

Reply

May 21, 2012 at 8:25 am Dear Ahmed,


Mir Thanks for appreciating my efforts, to
draw a complete route u need the same code
that is in the tutorial, all u need is to have more geo points. End of one Geo
Point will the the start of the next one and so on. By connecting multiple geo
points u can get the complete route. there are a number of ways to do this.
First , provide all Geo points Statically in the code as i have done, defined
three points drawing two lines. The second one would be to get the
Coordinates directly from the GPS and move along a path or u can even get
the coordinates by touching a multiple locations on the map and getting
coordinates from it. There can be many more but the basic logic stays the
same i.e, u need two points to draw a single line, 3 points to draw 2 lines and
so on.
Hope this helps.

http://mirnauman.wordpress.com/2012/04/26/android-google-maps-tutorial-part-7-dra... 08/10/2013
Android Google Maps Tutorial Part 7, Drawing A Path or Line Between Two Locat... Pgina 8 de 17

Reply

May 21, 2012 at 7:24 pm A dedicated person working whole


Shakeel (android Developer) heartedly for the welfare of
beginnersI think developing all these
application is his interest. Good Job..Keep it upThis person also helped me
lot.

Reply

May 22, 2012 at 7:41 pm Thanks a lot Mir!


Ahmed Youre right about the basic logic of
routing, but what I meant here is I believe
much more complicated .. it is about an algorithm that does the following:
1- calculates the several routes could be thousands, and decide the best
route among them.
2- recognizes google maps i.e recognize the streets, junctions etc and
draw the path along these streets which of-course must be provided by
google itself-.
So I think google must have these options for developers.

I hope my point was clear, and thanks anyway you were very helpful

Reply

May 24, 2012 at 1:17 pm Dear Ahmed,


Mir I dont know about that right now as i
have not explored it yet, but i ll go through
some googling. if i find something i write a tutorial about it and will share it
wid every1

Reply

May 25, 2012 at 5:04 pm thanks!


Ahmed Ill do the same

Reply

June 2, 2012 at 5:23 pm did you know how


sabu to display the name of the location or
address against the latitude and longitude ?..

Reply

June 3, 2012 at 5:10 pm yes , the process is called Geocoding,


Mir and getting coordinates from location
names is called Reverse Geo Coding. i ll soon
write a tutorial about it. check back soon.

Reply

June 7, 2012 at 10:02 am plz go through my tutorial that explains


Mir geocoding and reverse geocoding
http://mirnauman.wordpress.com/2012/06/07/android-google-maps-tutorial-
part-8-geocoding-and-reverse-geocoding/

http://mirnauman.wordpress.com/2012/04/26/android-google-maps-tutorial-part-7-dra... 08/10/2013
Android Google Maps Tutorial Part 7, Drawing A Path or Line Between Two Locat... Pgina 9 de 17

Reply

June 3, 2012 at 10:40 am Great tutorial Mir!


Alex Do you have any ideea what i should
use if i want to draw a line from my current
location to a placed geo point on the map?

Reply

June 3, 2012 at 5:09 pm hi aliex,


Mir its simple , first use my tutorial to get ur
current location and animate the map to the
current location, this will be location A. when u r done with that. than u must
have another geo point that will be location B, either u can hard code it or
touch a location on the map. get the touched location as location B. Than use
this tutorial to draw a path between these two points

Reply

June 11, 2012 at 12:26 pm Just wanted to say thank you, Great job
Bogdan man!

Reply

June 18, 2012 at 4:42 pm grate tutorial,


roman
i was interested to find something similar on
direction proc.
what i found:
a) KML usage : http://csie-tw.blogspot.com/2009/06/android-driving-
direction-route-path.html
b)how to draw a path with KML:
http://stackoverflow.com/questions/3109158/how-to-draw-a-path-on-a-map-
using-kml-file/3109723#3109723

any ideas : how to make it more simple way?

Reply

June 19, 2012 at 5:09 am i am currently working on KML parsing.


Mir i ll try to come up wid something
simpler.

Reply

June 18, 2012 at 5:10 pm great tutorial mir thank


manu u>!!!!!!!!!

Reply

July 4, 2012 at 12:41 pm Great its working fine,but i want to draw


pramod route from current location to target
location can you help me

Reply

http://mirnauman.wordpress.com/2012/04/26/android-google-maps-tutorial-part-7-dra... 08/10/2013
Android Google Maps Tutorial Part 7, Drawing A Path or Line Between Two Lo... Pgina 10 de 17

July 11, 2012 at 4:21 pm great totorial, now i make some app
zodiac where idont use tracking from google,
how i can load data longitude|lantitude from
database to draw point and overlay it in map(take from google)?

Reply

July 12, 2012 at 4:03 am there r two ways of doing that, first u
Mir create a kml file and parse it in android
code, get lat-long pairs form it and map them
on google maps. second method would be to store coordinates in sqlite db
and read data from it. my next tutorial in google maps section would be on
kml parsing. hope that will solve the problem

Reply

July 13, 2012 at 2:53 pm if i have some data in array(this data


zodiac take from database) lilke this for
example
(data1, lat, long,)
(data2, lat, long)
(data3, lat, long)
(data4, lat, long)

my question : can i draw line/straight line continues from data1->data2-


>data3->data4? thanks mir

Reply

July 18, 2012 at 5:35 am Thanks MirIm developing an android


Mohit app for bus route finder for sholapur city
just like mumbai bestbus app by chetan
temkar.spo plz will u help me in this..

Reply

July 18, 2012 at 5:41 pm sure i will but i can only guide u. as am
Mir stuck wid my office app development i
wont be able to go along step by step with the
whole application. i have worked on my next tutorial but i dont even have
time to document it and publish it. but as soon as am done wid the office
development. i ll be back on the track

Reply

August 8, 2012 at 1:52 pm Dear Mr. Mir Nauman Tahir,


Aprido Sandyasa Before i read your tutorial, my apps can
only draw line/path between two locations(in
my apps, source is my location). But now, my perspective has become more
broaden coz your tutorial shows me that the map can draw line/path between
more than two locations.
Thanks for your tutorial, i could develop more at my apps how to draw more
line in between a lot points.

http://mirnauman.wordpress.com/2012/04/26/android-google-maps-tutorial-part-7-dra... 08/10/2013
Android Google Maps Tutorial Part 7, Drawing A Path or Line Between Two Lo... Pgina 11 de 17

Best regards,
Aprido Sandyasa

Reply

August 8, 2012 at 6:20 pm Dear aprido sandyasa,


Mir thanks for appreciating my efforts. two
draw more line u need to have a set of
multiple coordinates. you can either store them in an array or in SQLite
DataBase or you can get the coordinates from a KML file (to get coordinates
from KML files u will need to manually parse the KML file to get each pair
of latitude and longitude). as u can see i have used 3 points. end point of one
line becomes the start of the other line and so on. all u need is two points to
draw a line, now its up to u how and from wat source u get those 2 points.
bottom line, to draw more lines between a lot of points is simple . make the
end point coodinates of a line as the start point for the next line and so on.
that way u will get a continuous line of multiple points

Reply

August 23, 2012 at 1:17 pm Mir Sir this program draws a line
sumit between two location or points can we
show the driving path between then.??

Reply

August 27, 2012 at 6:25 am ya we can show driving paths but for
Mir that we need to use the open street map
api. its on my tutorial agenda. will write
something about it , hopefully soon

Reply

September 27, 2012 at 5:25 pm i need some help


umar i am making a projrect in which i
received the GPS coordinates througth sms
into the google andriod phone .
my problem is i want to put the the coordinates from inbox of the andriod
phone in to the google map through some application.
Means the app should continuously get the coordinates from inbox and insert
the coordinates for real time tracking plzzzzzz plzzzzzzzzzz plzzzzzzzzzzz
any one help me out
Email:omar3228422552@gmail.com

Reply

September 28, 2012 at 4:08 am its not a big deal bro. will write a
Mir tutorial reading contents from sms in
inbox. after that the rest u will find in the
already published tutorials.

Reply

November 9, 2012 at 8:56 am

http://mirnauman.wordpress.com/2012/04/26/android-google-maps-tutorial-part-7-dra... 08/10/2013
Android Google Maps Tutorial Part 7, Drawing A Path or Line Between Two Lo... Pgina 12 de 17

Pete Heller Hello Mir,


I want to encapsulate the drawing function so
I can call it with two points. This is called by:
itemizedoverlay_line.drawLine(prev_map_point, map_point); //create a line
between previous and current point

To add the overlay I use this:


mapOverlays.add(itemizedoverlay_line); //add the overlay

This code is all executing (proved by the Log.d) but the lines are never
displayed (all my other layers are displaying correctly). Is there something
else I need to do to make the canvas visible? Here is the code:

public class MapLineStyleOverlay extends Overlay {


private ArrayList mOverlays = new ArrayList(); // not sure about this..
public MapLineStyleOverlay(){ }

public void drawLine(GeoPoint geoPt_1, GeoPoint geoPt_2) {


//Canvas canvas;
//MapView mapv;
boolean shadow = false;
super.draw(canvas, mapView, shadow);
//Configuring the paint brush
Paint paintBrush = new Paint();
paintBrush.setDither(true);
paintBrush.setColor(Color.RED);
paintBrush.setStyle(Paint.Style.FILL_AND_STROKE);
paintBrush.setStrokeJoin(Paint.Join.ROUND);
paintBrush.setStrokeCap(Paint.Cap.ROUND);
paintBrush.setStrokeWidth(12); //originally 4

Point p1 = new Point();


Point p2 = new Point();
Path line_path = new Path();

projection.toPixels(geoPt_2, p1);
projection.toPixels(geoPt_1, p2);

line_path.moveTo(p1.x, p1.y); //Move brush to start poing


line_path.lineTo(p2.x,p2.y); //set line (path) to end point
Log.d(debug,line_path points (p1.x=+p1.x+ p1.y= +p1.y+ ));

canvas.drawPath(line_path, paintBrush); //Actually draw the path

} // [END draw function]

} // [ END MapLineStyleOverlay ]

Reply

November 26, 2012 at 10:29 am Hey,Pete heler


Sagar Trehan I am facing the same problem as you
are.Have you got the solution of it.It got them
please explain me.Thanks in advance

Also thanks to Mir as this is the best map tutorial for me.

http://mirnauman.wordpress.com/2012/04/26/android-google-maps-tutorial-part-7-dra... 08/10/2013
Android Google Maps Tutorial Part 7, Drawing A Path or Line Between Two Lo... Pgina 13 de 17

Reply

November 29, 2012 at 12:08 pm hey mir awesome tut buddybut m


Durratulmazd Rokadia stuck in my app as i want to show real
time driving path in map means start location
will be location from where user starts driving and as he drives he should be
able to view the dotted lines till he reaches the destination.can you help me do
you need any more info then please let me know.thnx

Reply

November 29, 2012 at 12:20 pm To show the real time path that you have
sagar trehan followed while driving from source to
destination you need to run your app on real
android device.

For this as Mir had posted his awesome tutorial of how to draw a path
between between two latitude and longitude pair.You just have to follow that.

For it you have to use requestLocationUpdate() method in this you must pass
the minTime and minDistance after which you want to take latitude and
longitude points.You have to store all these latitude and longitude pair in
SQLite database later on reaching destination you must call the tutorial-7 of
Mir iteratively on the latitude and longitude pair present in SQLite database.

I have tested it today in my emulator with the help of emulator control.So I


think if you follow my advice then youll definitely do it.

Reply

November 29, 2012 at 12:16 pm after showing route i need to calculatae


Durratulmazd Rokadia distance between the start and end point.

Reply

November 29, 2012 at 12:41 pm thnx sagar i wl definately try it


Durratulmazd Rokadia
Reply

November 30, 2012 at 6:08 am hey sagar i tried googling about what
Durratulmazd Rokadia you adviced but didnt succeed can you
recomend some tutorials for the same or
sample codethnx..

Reply

November 30, 2012 at 6:46 am Hey Durratulmazd Rokadia,


sagar trehan
just give your email-id I will send my project
source to you.

Reply

November 30, 2012 at 6:53 am durrat_rokadia2007@yahoo.com


Durratulmazd Rokadia send it on above id
thnx

Reply

http://mirnauman.wordpress.com/2012/04/26/android-google-maps-tutorial-part-7-dra... 08/10/2013
Android Google Maps Tutorial Part 7, Drawing A Path or Line Between Two Lo... Pgina 14 de 17

December 3, 2012 at 8:23 am hey sagar thnx for helping ur code


Durratulmazd Rokadia helped lot but my issue was solved by
invoking google native google maps
application using intent and passing url as i ws in need to show turnby turn
direction.thnx lot for helping

Reply

December 3, 2012 at 8:41 am Thanks buddyIt my pleasure..


sagar trehan
Reply

December 18, 2012 at 6:48 am [...] Android Google Maps Tutorial Part 7, Drawing A
Android Google Maps Tutorial Part Path or Line Between Two Locations
4, Adding Menu & Some Additional (mirnauman.wordpress.com) [...]
Functionality Like Zooming, Reply
Changing Map View, Animating To
GPS Current Location Using Menu
Button. Mir

December 28, 2012 at 9:45 am [...]


Tutorial Membuat Marker Line di
Google Map | garisbesar
referensi : http://mirnauman.wordpress.com/2012/04/26/android-google-maps-tutorial-part-7-
drawing-a-path-or-line [...]
Reply

January 7, 2013 at 3:49 am Hi,


LiJuan If i want to draw a line between two
points which those points define by myself,
how should i do it? Those points are store in a text file

Reply

January 8, 2013 at 10:39 am Hi Mir,


Pravin Divraniya I just wanted to know that is it possible
in Android to draw particular area on map
view and fill it with specific color?
Your help would be highly appreciated.

Reply

January 14, 2013 at 6:14 pm Great tutor. Thanks tm Mr


mbakrizq @mirnauman.

Reply

February 21, 2013 at 4:26 am hi mir,


coolspirits can u plz tell how to show route
between two points (source and destination )
also alternative routes (without using website or kml file) we want this
functionality to be embedded in our application!! PLZ REPLY SOON!!

Reply

February 21, 2013 at 4:31 am there is no shortcut in Google Maps API


Mir V1. i ll explore the API V2, if google
provides anything that makes this route
drawing easy, i ll post the tutorial about it.

Reply

http://mirnauman.wordpress.com/2012/04/26/android-google-maps-tutorial-part-7-dra... 08/10/2013
Android Google Maps Tutorial Part 7, Drawing A Path or Line Between Two Lo... Pgina 15 de 17

February 21, 2013 at 4:39 am we are trying to copy google directions


coolspirits service . in our applicationeg. in
two textboxes we specify source and
destination (with google map behind the overlay) and when we press
enter the routes are displayed!
thanks

February 21, 2013 at 7:29 am Please reply!!!! its REALLY


coolspirits important!!!!! we have to submit first
deliverable!!!

Reply

February 24, 2013 at 6:16 pm Thanks for the tutorial.


Maimoonah I want to draw points with lines ?How?

Reply

February 26, 2013 at 8:16 am this articles is about drawing lines


Mir between two points. if u r trying to do
something else, please clearly explain ur
question in detail.

Reply

February 26, 2013 at 8:30 pm yes ,I want to show points or circles


Maimoonah above the lines ,
To show that this place is visited here
((not just lines))
Or in a more clear explanation: how to draw points on map in android?

February 26, 2013 at 8:43 pm Ive another question , in this tutorial


Maimoonah you have entered GPS coordinates (in
the code,without using GPS classes and
functions.
So I want to draw path if the location changed according to updates .so I
think I will need a database to store points, my question is :how to connect
between GPS and the Map-overlay class

To make it more clear :


se this inst in this tutorial :

GeoPoint gP1 = new GeoPoint(34159000,73220000);//starting point


Abbottabad
GeoPoint gP2 = new GeoPoint(33695043,73050000);//End point Islamabad

GeoPoint gP4 = new GeoPoint(33695043, 73050000);//Start point Islamabad


GeoPoint gP3 = new GeoPoint(33615043, 73050000);//End Point Rawalpindi

these instructions are put in :class MyOverlay ,and the


function :Onlocationchanged is put in another class , so how to do this?

(((((((( drawing path between 2 taken GPS locations))))))

http://mirnauman.wordpress.com/2012/04/26/android-google-maps-tutorial-part-7-dra... 08/10/2013
Android Google Maps Tutorial Part 7, Drawing A Path or Line Between Two Lo... Pgina 16 de 17

Thanks

Reply

February 27, 2013 at 6:34 am it is simple. the overlay class is written


Mir inside the main activity class in the same
file. so no extra effort of mechanism required
to access the gp1 and gp2 etc. just create and object of the overlay class and
use the objects inside it.

Reply

March 3, 2013 at 5:21 pm HiFriend,


myusro Good Tutorial, Thanks
Regards

Reply

March 3, 2013 at 5:25 pm [...] By. Mir Nauman Tahir in His Blog [...]
Drawing A Path or Line Between Reply
Two Locations Muhammad Yusro

March 24, 2013 at 12:39 pm Hi,could you please provide me the code
sonalshines for search location as well as
show_routes from source(current location as
GPS) to destination..I have followed your tutorial and have got the expected
output

Reply

March 28, 2013 at 4:24 am i have changed several machines in the


Mir past few month , survived some severe
crashes. so i dont have a compiled source code
of all the mini projects that you see on my blog. but i have included the
complete source code in the articles.

Reply

March 28, 2013 at 6:08 pm im having problem. how do i make it get


Moe location from edittext when a button is
clicked?

Reply

March 29, 2013 at 5:06 am


Mir
http://mirnauman.wordpress.com/2012/02/14/android-google-maps-tutorial-
part-4-adding-menu-some-additional-functionality-like-zooming-changing-
map-view-animating-to-gps-current-location-using-menu-button/

check the above article. this might solve alot of ur issues. its not actually a
button click, rather its a menu button that is clicked. but it will get u the idea
of how things work.

Reply

June 17, 2013 at 2:16 pm

http://mirnauman.wordpress.com/2012/04/26/android-google-maps-tutorial-part-7-dra... 08/10/2013
Android Google Maps Tutorial Part 7, Drawing A Path or Line Between Two Lo... Pgina 17 de 17

shishram Hi Mir,

First of all awesome tut!!, thanks for sharing your knowledge.

second, i am facing issue in showing route according to driving


direction ,what im getting only straight line so pls help me out here

thanks in advance for your consideration.

Reply

June 17, 2013 at 3:26 pm Dear Shishram,


Mir Thanks for the compliment. Google has
changed alot with the launch of Android
Google Maps API Ver 2.0. Everything that used to work with API Ver 1.0 is
history now. still if you managed to get the api key before google changed the
whole process you can develop but there will be a point when u will switch to
Android google maps API ver 2.0. I have started working on writing tutorials
for Android google maps API Ver 2.0. and will address every issue one by
one. so you need to follow my latest series of article to keep updated.
Now coming to ur specific issue. if you use openstreetview api or some other
open source streetview api, that will give you the right driving directions
along the paths as we see them in navigation section of google maps. I have
not written anything on using that api . u can check the links
openstreetmap.org and openstreetview.org
hope this helps,
thanks and best regards.

Reply

L E A V E A R E P LY

http://mirnauman.wordpress.com/2012/04/26/android-google-maps-tutorial-part-7-dra... 08/10/2013

You might also like