Map Scale and distance betwee two Location point

4 posts, 0 answers
  1. Gts
    Gts avatar
    17 posts
    Member since:
    Jul 2012

    Posted 17 Jul 2015 Link to this post

    Hi. I'm using virtualization layer and I want add pushpins into may use map scale and distance in pixel between 2 points.

    For example I have gps track with 1000 points. and I Have map zoomlevel 10

    I need to show pushpin on pan which have 20 pix distance between 2 pushpin

    var cPixl = eventArgs.Layer.MapControl.SpatialReference.GeographicToLogical(currentPoint);
     
    var nPixel = eventArgs.Layer.MapControl.SpatialReference.GeographicToLogical(nextPoint);
     
    var aPix = eventArgs.Layer.MapControl.SpatialReference.GeographicToLogical(lastAdded);
                             
    var pixDist = Math.Sqrt(Math.Pow(nPixel.X - cPixl.X, 2) + Math.Pow(nPixel.Y - cPixl.Y, 2));
     
    var lastDist = Math.Sqrt(Math.Pow(nPixel.X - aPix.X, 2) + Math.Pow(nPixel.Y - aPix.Y, 2));
    use this code I can convert gps point to pixel and get distance between 2 coordinate in pixel.

    Now I need to check lastDist with some constant variable for current zoom, and if this distance >= that this var I must add pushpin.

    But I don't know how can I calculate this variable for different zoom level.

    for example for zoom level I want that distance between 2 markers will be 20px, but eventArgs.Layer.MapControl.SpatialReference.GeographicToLogical return value between 0 and 1this mean that calculated distance will be between 0 and 1 too. 

  2. Martin
    Admin
    Martin avatar
    1099 posts

    Posted 21 Jul 2015 Link to this post

    Hello Artem,

    I am not sure that I understand your  requirement. Can you please prepare a small example that demonstrates your implementation? Also, drawings of the expected result will be useful. This will help me in better understanding your case and assist you further.

    Keep in mind that the GeographicToLogical() method of the SpatialReference return the logical latitude and longitude. You can see the following examples that explains the how to logical point is related to the location:
    • If we have a Location at (0, 0)  - at the map's center, where the equator and Greenwitch crosses - its logical point will be (0.5, 0.5)
    • If we have a Location at (0, 180), its logical point will be around (1, 0.5)
    • If we have a Location at (85, 0), its logical point will be around (0.5, 0)
    • If we have a Location at (85, 180), its logical point will be around (1, 0)
    Basically, the logical point is the location in a relative units based on the map's latitude and longitude. Note that the Latitude of the location corresponds to the Y of the logical point and the Longitude to the X.

    If you know the distance between the points in km or miles (the unit defined in the map's DistanceUnit property), you can use the GetPixelsDistance() method of the map. You can also try the GetPixelSizeAtZoomLevel() method - basically, you can use the given locations to create a LocationRect and pass it to the method in order to get the pixel size.

    I hope this information helps.

    Regards,
    Martin
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. DevCraft banner
  4. Gts
    Gts avatar
    17 posts
    Member since:
    Jul 2012

    Posted 22 Jul 2015 in reply to Martin Link to this post

    Thanks for the reply. Maybe I write not clear description.

    I'll try again. I have two coordinate and 2 pushpin on map. I ned to know distance between this position in pixel, and distance must be relative to MapControl. not logical, or maybe logical but value must be > 0

    I prepare small picture with example
  5. Martin
    Admin
    Martin avatar
    1099 posts

    Posted 24 Jul 2015 Link to this post

    Hi Artem,

    Thank you for the clarification. You can get the distance between two locations on the map in pixels using the following approach:
    • Convert the locations to Point objects using the GetPoint() method of the Location object.
      var startPoint = startLocation.GetPoint(this.map);
      var endPoint = endLocation.GetPoint(this.map);
    • Calculate the distance between the points
      double distance = GetDistanceBetweenPoints(startPoint, endPoint); 
      //......................
      private double GetDistanceBetweenPoints(Point startPoint, Point endPoint)
      {
          double a = (double)(endPoint.X - startPoint.X);
          double b = (double)(endPoint.Y - startPoint.Y);
       
          return Math.Sqrt(a * a + b * b);   
      }
    Please give this approach a try and let me know if it works for you.

    Regards,
    Martin
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top