Welcome to MapForums!

Register, sign in, or use Facebook Connect above to join in and participate in the forum.

When you are signed in, this message, the ads in this row, and the red-underlined link ads all go away.

Subscribe to receive our newsletter.
Subscribe Unsubscribe
Results 1 to 10 of 10

How do I loop my dataset of Lat/Long into a map using C#?

This is a discussion on How do I loop my dataset of Lat/Long into a map using C#? within the MapPoint Desktop Discussion forums, part of the Map Forums category; Using C# & MP2K4, I already have a dataset that contains my Lat/Long values that I want to plot onto ...

  1. #1
    trinity is offline Junior Member White Belt
    Join Date
    Dec 2005
    Posts
    3

    How do I loop my dataset of Lat/Long into a map using C#?

    Using C# & MP2K4, I already have a dataset that contains my Lat/Long values that I want to plot onto a map but I don't know the correct syntax inside my foreach loop. PLEASE HELP!!!!

    I don't need to use GetLocation since I already have the coordinates. I just want to shove them onto a map and display them.

    //populate my dataset
    System.Data.DataSet myDataSet = new System.Data.DataSet();
    myDataAdp.Fill(myDataSet,"myTable");

    //display a map
    MapPoint.Map myMap = axMappointControl1.NewMap(MapPoint.GeoMapRegion.ge oMapNorthAmerica);
    MapPoint.DataSet myMapDS = myMap.DataSets.AddPushpinSet("New PushPins");

    foreach(DataRow DR in myDataSet.Tables["myTable"].Rows)
    {
    ??????????
    }

  2. #2
    Dazzer is offline Senior Member Green Belt
    Join Date
    Sep 2003
    Posts
    103
    You need to look at the GetLocation method

    I dont know about doing this in C# but in VB .Net it would be something along the lines of


    Code:
    Dim objLoc as mappoint.location
    Dim objMap as Mappoint.map
    
    ObjLoc = GetLocation(50.333,-1.222, 100)
    
    
    objMap.AddPushpin(objLoc)
    Getlocation(Lat,Lon,Altitude)

    Note this is completely untested but I have done it before and i seem to remember its something along these lines, unfortunatly i'm not near somewhere I could test it at the moment.

  3. #3
    Dazzer is offline Senior Member Green Belt
    Join Date
    Sep 2003
    Posts
    103
    Sorry I didn't read your previous post properly, you said you dont need to use getlocation but perhaps you do.

    Again in VB

    Code:
    Dim dr as datarow
    
    For each Dr in myDataSet.Tables["myTable"].Rows
    
    
    ObjLoc = GetLocation(dr("Lat"),dr("Lon"), 100) 
    
    
    objMap.AddPushpin(objLoc)
    
    
    Next

  4. #4
    Wilfried is offline Senior Member Black Belt
    Join Date
    Nov 2004
    Location
    Belgium
    Posts
    2,433
    Hi,

    For best results make the Altitude argumen 1 instead of 100. Many mappoint calculations get inapropriate if you view it to high If you want to shoot someone you also want to be close to not miss the target

  5. #5
    trinity is offline Junior Member White Belt
    Join Date
    Dec 2005
    Posts
    3
    Thanks for responding so quickly, but I don't want to use GETLOCATION as I already know where it is since I have long/lat in my dataset.

    Anybody else have a suggestion.? I highly appreciate it if someone can help in c# please.

  6. #6
    Dazzer is offline Senior Member Green Belt
    Join Date
    Sep 2003
    Posts
    103
    What wilfred said about the altitude makes sense, I just put 100 in as an example.

    trinity as I understand it your saying you dont want to use GetLocation because you already have the lat/lon but I think your missing the purpose of GetLocation.

    Getlocation isn't used to return a set of coordinates but to return a location object on a set of coordinates that you pass it, as my code shows. As you already know the coordinates your working with you can put this in the GetLocation method to return a location object, once you have the location object you can place a pushpin or do whatever else it is that you need to do.

    Perhaps i'm misunderstanding your question but this seems the logical answer to me.

  7. #7
    Wilfried is offline Senior Member Black Belt
    Join Date
    Nov 2004
    Location
    Belgium
    Posts
    2,433
    Quote Originally Posted by trinity
    GETLOCATION
    Please dont use capitals. It is like you shout If you wants to emphrase a word use _ or use single / double quotes or make it bold text. This is very common use in news / forums / email.

    thanks

  8. #8
    trinity is offline Junior Member White Belt
    Join Date
    Dec 2005
    Posts
    3
    You were right, I did misunderstand GetLocation, this is what I am using now. Thank you everybody!

    MapPoint.Location mapLoc;
    double dblLon;
    double dblLat;

    foreach (DataRow dataRow in myDataSet.Tables["myTable"].Rows)
    {
    dblLat = Convert.ToDouble(dataRow["Latitude"]);
    dblLon = Convert.ToDouble(dataRow["Longitude"]);

    mapLoc = myMap.GetLocation(dblLat, dblLon, 100);
    myMap.AddPushpin(mapLoc, "PP");
    }

  9. #9
    Wilfried is offline Senior Member Black Belt
    Join Date
    Nov 2004
    Location
    Belgium
    Posts
    2,433
    Hi,

    Glad it works now for you

    Code:
     mapLoc = myMap.GetLocation(dblLat, dblLon, 100);
    Please set altitude to 1 !!! Some methods will have a high dillusion of precision if you go so hight.

  10. #10
    Dazzer is offline Senior Member Green Belt
    Join Date
    Sep 2003
    Posts
    103
    Glad we could help, the Mappoint help is actually suprisingly good at explaining a lot of its methods and properties if you continue to have problems. Of course this forum is also fantastic, its helped me a lot in the past !

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Creating New Dataset
    By Yazzy in forum MapPoint Desktop Discussion
    Replies: 4
    Last Post: 08-23-2005, 08:20 AM
  2. Importing Lat and Long directly to Pushpin Dataset?
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 12-21-2004, 09:00 PM
  3. How do you loop through the stops on a route?
    By petemarkham in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 11-11-2003, 12:06 PM
  4. DataSet Modifications ?
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 09-12-2003, 03:44 AM
  5. Need help: return to loop and continue processing
    By David Kachuck in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 11-13-2002, 11:38 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25