Draw Markers within a radius of x km / miles

Sep 28, 2009 at 5:01 PM

Hi, I'm not sure how to describe what I'm after! I'm just hoping you could explain how or if this is possible...

Is there a way to produce an overlay for a specific area similar to this example I found @ http://www.flex888.com/lab/geoweb/geoyahoo/

I have a database table of named markers with lat & lng. i.e. List of Hotels, Hospitals, Airports etc

What I need to do is show any markers within a specified radius of current location.

e.g. Show all hotels within 5 miles of current location and draw a semi-transparant circle on the map to indicate the range.

Also, I'm using WPF...

Loving this project, thanks in advance...


Sep 28, 2009 at 5:54 PM

try something like this ;}

         double areaRadius = 5.0; // km
         List<PointLatLng> objects = new List<PointLatLng>();
         var objectsInArea = objects.Where(p => GMaps.Instance.GetDistance(MainMap.CurrentPosition, p) <= areaRadius);
         var maxDistObject = (from p in objectsInArea
                              orderby GMaps.Instance.GetDistance(MainMap.CurrentPosition, p) descending
                              select new
                                 Pos = new PointLatLng(p.Lat, p.Lng),
                                 Dist = GMaps.Instance.GetDistance(MainMap.CurrentPosition, p)

         // add objects to zone
         foreach(var o in objectsInArea)
            GMapMarker it = new GMapMarker(pos.Value);
               it.ZIndex = 55;

               var s = new System.Windows.Controls.Button();
               s.Content = "object: " + o;

               it.Shape = s;

         // add zone circle
         GMapMarker it = new GMapMarker(MainMap.CurrentPosition);
            it.ZIndex = 55;

            var pxCenter = MainMap.FromLatLngToLocal(MainMap.CurrentPosition);
            var pxBounds = MainMap.FromLatLngToLocal(maxDistObject.Pos);

            double a = (double)(pxBounds.X - pxCenter.X);
            double b = (double)(pxBounds.Y - pxCenter.Y); 
            var pxCircleRadius = Math.Sqrt(a * a + b * b);

            // set area size, you should really create ellipse or something here ;}
            var s = new System.Windows.Controls.Button();
            s.Width = pxCircleRadius;
            s.Height = pxCircleRadius;

            it.Shape = s;



Sep 28, 2009 at 7:05 PM

I've just included it in wpf demo ;}

Sep 29, 2009 at 9:23 AM

Perfect thank you very much

Nov 9, 2009 at 12:27 PM
Edited Nov 9, 2009 at 12:29 PM

Update: I've added the ability for the user to set the zone area. However, the zone circle does not update onto the map or is drawn in top left corner!

The zone circle will only be shown after altering the zone level...

Any ideas why or how to set correctly?

<GroupBox Header="zone" HorizontalAlignment="Right" Name="zone" Width="169" Margin="0,465,11,283" Height="55" VerticalAlignment="Top">
   <StackPanel Orientation="Horizontal">
      <TextBox x:Name="Distance" Margin="2" FontSize="14" VerticalAlignment="Center" Text="{Binding Path=Double, StringFormat=F3}" Width="50"/>
      <Label Content="km" Width="25" VerticalAlignment="Center"/>
      <Button x:Name="Zone" Content="Show Zone" Margin="2" Height="21.04" VerticalAlignment="Center" Click="Zone_Click"/>

      private void Zone_Click(object sender, RoutedEventArgs e)
          button10_Click(null, null);
          AddDemoZone(double.Parse(Distance.Text), MainMap.CurrentPosition, markerobjects);
Nov 9, 2009 at 1:43 PM

because you donot use Offset, use ForceToUpdate...