我是 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,但它不起作用。我已经有这个错误很长时间了。有人可以帮忙吗!谢谢