How to Add Markers and Routes

May 26, 2009 at 10:17 AM
Edited May 26, 2009 at 10:48 AM

Hi Radioman,

       I am not understanding about adding markers and displaying routes on the map. This bellow code contains 5 markers and i need to connect these markers with one poly line guide me regarding this

 private void UserDefined_Click(object sender, EventArgs e)

{

objects.Markers.Clear();

routes.Routes.Clear();

PointLatLng point1 = new PointLatLng(17.4180196850649, 78.3441817760468);<font size="2"> PointLatLng point2 = new PointLatLng(17.4186338967422, 78.3431839942932);

 

 

PointLatLng point3 = new PointLatLng(17.4193197640071, 78.3420038223267);

 PointLatLng point4 = new PointLatLng(17.4203843886888, 78.3401584625244);

 PointLatLng point5 = new PointLatLng(17.4218380008271, 78.3377659320831);

 GMapMarker m1 = new GMapMarker(point1);

GMapMarker m2 = new GMapMarker(point2);

 GMapMarker m3 = new GMapMarker(point3);

GMapMarker m4 = new GMapMarker(point4);

 GMapMarker m5 = new GMapMarker(point5);

m1.ToolTipText ="HI1";

m2.ToolTipText ="HI2";

m3.ToolTipText ="HI3";

m4.ToolTipText ="HI4";

m5.ToolTipText ="HI5";

objects.markers.add(m1);

objects.markers.add(m2);

objects.markers.add(m3);

objects.markers.add(m4);

objects.markers.add(m5);

 mainmap.reloadmap();

}

thanks & regards

asif

Coordinator
May 26, 2009 at 1:32 PM
     void Test()
      {
         PointLatLng point1 = new PointLatLng(17.4180196850649, 78.3441817760468);
         PointLatLng point2 = new PointLatLng(17.4186338967422, 78.3431839942932);
         PointLatLng point3 = new PointLatLng(17.4193197640071, 78.3420038223267);
         PointLatLng point4 = new PointLatLng(17.4203843886888, 78.3401584625244);
         PointLatLng point5 = new PointLatLng(17.4218380008271, 78.3377659320831);

         GMapMarker m1 = new GMapMarkerGoogleGreen(point1);
         GMapMarker m2 = new GMapMarkerGoogleGreen(point2);
         GMapMarker m3 = new GMapMarkerGoogleGreen(point3);
         GMapMarker m4 = new GMapMarkerGoogleGreen(point4);
         GMapMarker m5 = new GMapMarkerGoogleGreen(point5);

         m1.ToolTipText ="HI1";
         m2.ToolTipText ="HI2";
         m3.ToolTipText ="HI3";
         m4.ToolTipText ="HI4";
         m5.ToolTipText ="HI5";

         m1.TooltipMode = MarkerTooltipMode.Always;
         m2.TooltipMode = MarkerTooltipMode.Always;
         m3.TooltipMode = MarkerTooltipMode.Always;
         m4.TooltipMode = MarkerTooltipMode.Always;
         m5.TooltipMode = MarkerTooltipMode.Always;

         GMapOverlay objects = new GMapOverlay(MainMap, "stops");
         {
            objects.Markers.Add(m1);
            objects.Markers.Add(m2);
            objects.Markers.Add(m3);
            objects.Markers.Add(m4);
            objects.Markers.Add(m5);
         }
         MainMap.Overlays.Add(objects);

         // add route
         List route = new List();
         {
            route.Add(point1);
            route.Add(point2);
            route.Add(point3);
            route.Add(point4);
            route.Add(point5);
            route.Add(point1);
         }
         MapRoute r = new GMapRoute(route, "track");
         routes.Routes.Add(r);

         MainMap.ZoomAndCenterMarkers("stops");
      }
// simple ;}
May 29, 2009 at 7:27 AM

Hi Radioman,

        Thank you, one more doubt how to change route color? i am using the following code for changing route color but its not changing at all. guide me regarding this.

routes.RoutePen.Color = Color.green;

Regards

Asif

 

Coordinator
May 29, 2009 at 7:36 AM
GMapRoute r = new GMapRoute(route, "test");
{
  r.Color = Color.Blue;
}
routes.Routes.Add(r);
Sep 22, 2009 at 10:32 AM

Hi Radioman,

I'm trying to add routes on my map but I have some problems here :S

I tried to use your example code but I have erros. I can't understand this line:

routes.Routes.Add(r);

I can see the markers on map but not the route. This is the best way to draw routes?

Tks a lot!

 

Sep 22, 2009 at 11:18 AM

Ok I solve the problem adding this lines:

GMapOverlay routes = new GMapOverlay(MainMap, "routes");
routes.Routes.Add(testes);
MainMap.Overlays.Add(routes);

But now I have another problem. This route doesn't show me the directions to next point,I mean, the route doesn't follow the roads to get the next point.

Should I use GetRouteBetweenPoints function ?

Tks again and sorry for my english!

 

 

Coordinator
Sep 22, 2009 at 4:59 PM

you can add any point in the route, but if you want correct route generated automatically, use that function or any other service of that type

..and do not sorry for English, i catch your mind ;}

Sep 22, 2009 at 5:22 PM

Tks a lot for your help radioman. It's done :D

I used GetRouteBetweenPoints and it works perfectly :P

Now I have another doubts. It's not related with this topic but I write right here:

1-How can I show on the map the original zoom bar and type map menu?

2-How can I use the right button mouse event on left button?

Tks again!

Coordinator
Sep 22, 2009 at 5:26 PM

1 - use slidebar ;}

2 - use DragButton property ;}

Sep 22, 2009 at 5:58 PM

1 - which slidebar? I really want to use the original zoom bar? Is it possible?

2- done :P

3-Another doubt: I'm using the google maps api to find a given local coordinates (cause I didn't find the right function to do that). So I use the follow url:

http://maps.google.com/maps/geo?q=BLABLA

In some cases the same given name exists many times, for example, if I use the string "X Street" perhaps exists 2 diferent places with the same name. How can I know every places with that name?

If there is a better way to find coordinates I can change my code :D

Coordinator
Sep 22, 2009 at 6:17 PM

1 - what original? ;]

3 - it will be some day! ;}

Sep 24, 2009 at 11:32 AM

Hello again.

Sorry for my late answer.

1- I was talking about the zoom slidebar on google maps (http://maps.google.com/). On up left corner. Is it possible to show? if not I will use a slidebar like in demo.

3-Ok I have a version to do this:D search for a local (string) and get many coordinates. I'm using a XML answer to get different coordinates. I give the code here if you want to use it.

private List<Destino> loadXmlFile()
        {
            List<Destino> arrayCoordinates = new List<Destino>();
            XmlDocument doc = new XmlDocument();
            String url = "http://maps.google.com/maps/geo?q=" + textBox1.Text + "&output=xml&sensor=true&oe=utf8";
            Console.WriteLine(url);
            doc.Load(url);

            XmlTextReader reader = new XmlTextReader(url);
            XmlNodeList memberNodes = doc.SelectNodes("//kml");
            String localDestino = "";
            String coordDestino = "";
            while (reader.Read())
            { 
                switch (reader.NodeType)
                {
                    case XmlNodeType.Element:
                        if (reader.Name.Equals("address"))
                        {
                            localDestino = reader.ReadElementString();
                            
                        }
                        else if (reader.Name.Equals("coordinates")) {
                            coordDestino = reader.ReadElementString();
                            arrayCoordinates .Add(new Destino(localDestino,coordDestino));                            
                        }
                        break;                    
                }
            }            
            return getCoordinates(arrayCoordinates );            
        }

This is just an example. This code gets the coordinates and address also. Hope its useful :D

Bye

 

 

Coordinator
Sep 24, 2009 at 11:41 AM

1 - this is not browser based control, so it's impossible

2 - great!

Sep 24, 2009 at 4:12 PM

radioman,

 

On your point no.1 about it being impossible and using the other API functions of Google from within VB/VC , well some time ago i came across a control called VirtualEarth and it hosted a WebBrowse control

but used this WebBrowser control to send/recieved API functions.

I expanded it to work as i wanted, including adding pins etc, but also enabled Google options such as zooms etc.  Anyway it demonstrates how to get to the Goolge API using a bit of clever dynamically build java.

Let me have a link where i can drop a copy of the program for you. It is a while since i used it, and it may not even compile , but you can see the code in the VEControl.vb  file   ShowInitalMap sub.

 

Paul.

Coordinator
Sep 24, 2009 at 5:40 PM

can you send it to me at radioman.lt@gmail.com ?

Sep 24, 2009 at 6:08 PM

hmm, hotmail just returned the email to that address,

any other address to try?

 

 

Coordinator
Sep 24, 2009 at 6:11 PM

skydrive?

Sep 24, 2009 at 6:30 PM

ive uploaded as a patch

 

Coordinator
Sep 25, 2009 at 8:49 PM

interesting ;}