title: How to convert geographical coordinates to pixels?
body: <p>I am developing wpf application. I have one static world map of 500 width and 500 height. I have one form in my application. In this from user enters the latitude and longitude and submit the details. I want to show the exact location of these latitude and longitude on my static map. So I am trying to convert these latitude and longitude into pixels. I am using ellipse to show the circle on my static map. How should I convert the geographical coordinates into pixels in C# ? Can you please provide me any code or link through which I can solve the above issue ? My question is similar to the link </p>
  
  <p><a href="https://stackoverflow.com/questions/2651099/convert-long-lat-to-pixel-x-y-on-a-given-picure">Convert long/lat to pixel x/y on a given picture</a></p>
  
  <p>I found this link useful.</p>
  
  <p>Edit :
  I have used the link</p>
  
  <p><a href="http://code.google.com/p/geographical-dot-net/source/browse/trunk/GeographicalDotNet/GeographicalDotNet/Projection/GoogleMapsAPIProjection.cs" rel="nofollow noreferrer">http://code.google.com/p/geographical-dot-net/source/browse/trunk/GeographicalDotNet/GeographicalDotNet/Projection/GoogleMapsAPIProjection.cs</a></p>
  
  <p>and written the following code</p>
  
  <pre><code>GoogleMapsAPIProjection googleApiProjObj = new GoogleMapsAPIProjection(0);
              float x = 18.29F;
              float y = 73.57F;
              System.Drawing.PointF p1 = new System.Drawing.PointF(x,y);
              System.Drawing.PointF p2 =googleApiProjObj.FromCoordinatesToPixel(p1);
  
              //CircleEllipse.Margin = new Thickness(longitudePixels,latitudePixels, 0, 0);
              CircleEllipse.Margin = new Thickness(p2.X, p2.Y, 0, 0);
              CircleEllipse.Visibility = Visibility.Visible;
  </code></pre>
  
  <p>18.29 and 73.57 are lat and log of Pune city in India. In the above code p2.x giving me 141 and p2.y giving me 49. So the above code not showing me the Pune location on map. My xaml code is as follows</p>
  
  <pre><code>&lt;ScrollViewer HorizontalScrollBarVisibility="Auto" Grid.Row="4" Width="500" Height="500" Background="Gray"&gt;
              &lt;Grid&gt;
                  &lt;Image Margin="0,0,0,0" x:Name="MapImage" Source="Images\World-Blank-Map.png" Stretch="Fill" Width="500" Height="500" &gt;&lt;/Image&gt;
                  &lt;Ellipse Canvas.Top="50" 
        Canvas.Left="50" 
        Fill="Red" 
        Height="5"
        Width="5"
        Visibility="Collapsed"
        StrokeThickness="4"                     
  
        x:Name="CircleEllipse"
        HorizontalAlignment="Left"
        VerticalAlignment="Top"
        Margin="0,0,0,0" /&gt;
              &lt;/Grid&gt;
          &lt;/ScrollViewer&gt;
  </code></pre>