0

我是 Windows Phone 7 开发的新手。我最近下载并试用了 Arcgis 示例地图,在更改 TiledMapserverlayer 的 URL 后它给了我这个错误。

Invalid spatial reference. Spatial reference must match map's spatial reference. Clear the map layers collection prior to changing the spatial reference.

.xaml

            <esri:GraphicsLayer ID="MyGraphicsLayer">
                <esri:GraphicsLayer.Graphics>
                    <esri:Graphic Symbol="{StaticResource RedMarkerSymbol}">
                        <esriGeometry:MapPoint X="11560518.5450925" Y="153495.271364825">


                        </esriGeometry:MapPoint>
                    </esri:Graphic>
                </esri:GraphicsLayer.Graphics>
            </esri:GraphicsLayer>

            <esri:ArcGISTiledMapServiceLayer ID="MyLayer" 
                Url="http://www.onemap.sg/ArcGIS/rest/services/basemap/MapServer" />
        </esri:Map>

。CS

    public partial class Map : PhoneApplicationPage
{
    GeoCoordinateWatcher _watcher;
    Graphic _graphicLocation;
    private static ESRI.ArcGIS.Client.Projection.WebMercator mercator =
      new ESRI.ArcGIS.Client.Projection.WebMercator();
    bool initialLoad = true;

    public Map()
    {
        InitializeComponent();

        _graphicLocation = (MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer).Graphics[0];

        _watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High);
        _watcher.MovementThreshold = 20;

        _watcher.StatusChanged += watcher_StatusChanged;
        _watcher.PositionChanged += watcher_PositionChanged;

        // Start data acquisition
        _watcher.Start();
    }

    void watcher_StatusChanged(object sender, GeoPositionStatusChangedEventArgs e)
    {
        switch (e.Status)
        {
            case GeoPositionStatus.Disabled:
                // The location service is disabled or unsupported.
                // Alert the user
                StatusTextBlock.Text = "Location is unsupported on this device";
                break;
            case GeoPositionStatus.Initializing:
                // The location service is initializing.
                // Disable the Start Location button
                StatusTextBlock.Text = "Initializing location service";
                break;
            case GeoPositionStatus.NoData:
                // The location service is working, but it cannot get location data
                // Alert the user and enable the Stop Location button
                StatusTextBlock.Text = "Data unavailable";
                break;
            case GeoPositionStatus.Ready:
                // The location service is working and is receiving location data
                // Show the current position and enable the Stop Location button
                StatusTextBlock.Text = "Ready - retrieving data";
                break;
        }
    }

    void watcher_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
    {
        _graphicLocation.Geometry = mercator.FromGeographic(new MapPoint(e.Position.Location.Longitude, e.Position.Location.Latitude));

        // Use horizontal accuracy (returned in meters) to zoom to the location
        if (initialLoad)
        {
            Envelope rect = new Envelope(
                (_graphicLocation.Geometry as MapPoint).X - (e.Position.Location.HorizontalAccuracy / 2),
                (_graphicLocation.Geometry as MapPoint).Y - (e.Position.Location.HorizontalAccuracy / 2),
                (_graphicLocation.Geometry as MapPoint).X + (e.Position.Location.HorizontalAccuracy / 2),
                (_graphicLocation.Geometry as MapPoint).Y + (e.Position.Location.HorizontalAccuracy / 2));

            MyMap.ZoomTo(rect.Expand(20));

            initialLoad = false;
        }
        else
        {
            MyMap.PanTo(_graphicLocation.Geometry);
        }
    }

    private void PhoneApplicationPage_Unloaded(object sender, RoutedEventArgs e)
    {
        _watcher.Stop();
    }}

我尝试了许多解决方案,例如添加 wkid,但它不起作用。我已经有这个错误很长时间了。有人可以帮忙吗!谢谢

4

1 回答 1

1

一般来说,您不应该混合 SpatialReferences。调用 Map.Pan,将 Extent 更改为 SRef 与 Map 的 SRef 不同的未投影几何体的缩放将导致抛出异常。当 GPS 位置发生变化时,您正试图移动具有差异 SRef 的地图,这会导致异常。如果您先投影 GPS 点,您将不会遇到这个问题。为此使用 GeometryService。顺便看看他们工具包中的 API 的 GpsLayer,因为它可以节省您在上面手动编写的大量代码。还要在上面设置一个 ProjectionService ,事情应该对你有用。

干杯:)

于 2013-03-19T16:50:59.150 回答