Select to view content in your preferred language

Unable to Plot Latitude and Longitude as a graphic on Bing Map Tile Layer Correctly

849
2
11-26-2012 10:29 PM
sreeharshansamineni
Emerging Contributor
Hi,
i'm trying to plot latitude and longitude as a graphic on Bing map tile layer.
but that graphic is not displaying at the correct location.
can anybody give me their valuable suggestions on the same.

here is the code:
Xaml View:

<UserControl x:Class="SilverlightSample.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:esri="http://schemas.esri.com/arcgis/client/2009"
    xmlns:j="http://schemas.microsoft.com/expression/2010/interactivity"
    xmlns:esriBehaviors="clr-namespace:ESRI.ArcGIS.Client.Behaviors;assembly=ESRI.ArcGIS.Client.Behaviors"
    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
    xmlns:bing="clr-namespace:ESRI.ArcGIS.Client.Bing;assembly=ESRI.ArcGIS.Client.Bing">

    <Grid x:Name="LayoutRoot" Background="White">
        <Grid.Resources>
<esri:SimpleMarkerSymbol x:Key="RedMarkerSymbol" Color="Red" Size="12" Style="Circle" />

        </Grid.Resources>
<esri:Map x:Name="MyMap" WrapAround="True" Extent="2172951.24,-2977568.64,15646541.00,6483665.35" Loaded="MyMap_Loaded">
            <esri:Map.Layers>
                <bing:TileLayer ID="Bing Layer" LayerStyle="Road" ServerType="Production" Visible="True"
                   Token="AtzVxHIwGvcsSLalf3ryOQrw9litxzSCSzpJxRgZNECjli-arkrbowrm2HI8xrv0" InitializationFailed="Layer_InitializationFailed" />
<esri:GraphicsLayer ID="PointsGraphicsLayer">
                   
                </esri:GraphicsLayer>
</esri:Map.Layers> 
</esri:Map>

.cs:

namespace SilverlightSample
{
    public partial class MainPage : UserControl
    {
        private static ESRI.ArcGIS.Client.Projection.WebMercator mercator =
             new ESRI.ArcGIS.Client.Projection.WebMercator();
        GraphicsLayer PointsGL = null;
        public MainPage()
        {
            InitializeComponent();
            //LoadGraphics();
            PointsGL = MyMap.Layers["PointsGraphicsLayer"] as GraphicsLayer;
        }
  private void CreatePoint(string lt, string lon)
        {
            double i_lt = Convert.ToDouble(lt) ;
            double i_lon = Convert.ToDouble(lon);
             SpatialReference SR=MyMap.Layers[0].SpatialReference;
            PointsGL.ClearGraphics();
            MapPoint P = new MapPoint(i_lt, i_lon);//,new SpatialReference(102100));

            Graphic graphic = new Graphic()
            {
                Geometry = P,// mercator.FromGeographic(P),
              
                //mercator.FromGeographic(new MapPoint(coordinateList.Coordinates.X, coordinateList.Coordinates.Y)),
                Symbol = LayoutRoot.Resources["RedMarkerSymbol"] as SimpleMarkerSymbol,
               
            };
            PointsGL.Graphics.Add(graphic);
            MyMap.PanTo(graphic.Geometry);
    
        }
    }
0 Kudos
2 Replies
DominiqueBroux
Esri Frequent Contributor
MapPoint P = new MapPoint(i_lt, i_lon);//,new SpatialReference(102100)); 

Graphic graphic = new Graphic() 

Geometry = P,// mercator.FromGeographic(P),


You have to set the WGS84 spatial reference to your mappoint.
Something like:
MapPoint P = new MapPoint(i_lt, i_lon,new SpatialReference(4326));

            Graphic graphic = new Graphic()
            {
                Geometry = mercator.FromGeographic(P),
0 Kudos
sreeharshansamineni
Emerging Contributor
Thank you very much dbroux
It Solved my problem.

In continuation to this i want some suggestion from you on the below Question
How to add lat and long as a point to  point feature layer(not as a graphic on the map, it should update to database also) that is published as a feature service
0 Kudos