C# ConvertViewportPointToGeoCoordinate在WP8.0中提供空值

C# ConvertViewportPointToGeoCoordinate在WP8.0中提供空值,c#,windows-phone-8,C#,Windows Phone 8,我试图得到地图控件左上角和右下角的坐标。我使用ConvertViewportPointToGeoCoordinate来实现这一点,但出于某种原因,它在使用WP 8.0时不会产生值,但在使用WP 8.1时会起作用。你知道为什么会这样吗 XAML: 在转换之前,需要将俯仰设置为与缩放级别相等 GeoCoordinate topLeft = new GeoCoordinate(); GeoCoordinate bottomRight = new GeoCoordinate(); try { /

我试图得到地图控件左上角和右下角的坐标。我使用ConvertViewportPointToGeoCoordinate来实现这一点,但出于某种原因,它在使用WP 8.0时不会产生值,但在使用WP 8.1时会起作用。你知道为什么会这样吗

XAML:


在转换之前,需要将俯仰设置为与缩放级别相等

GeoCoordinate topLeft = new GeoCoordinate();
GeoCoordinate bottomRight = new GeoCoordinate();
try
{
    //Set pitch to zoom level so ConvertViewpointToGeoCoordinate does not return null in 8.0
    RMap2.Pitch = RMap2.ZoomLevel;
    topLeft = RMap2.ConvertViewportPointToGeoCoordinate(new Point(0, 0));
    bottomRight = RMap2.ConvertViewportPointToGeoCoordinate(new Point(400, 400));
}
catch {  }
//Resets pitch to 0.0 so the map looks 2D
//These lines of code execute so quickly the user will not see the pitch change
RMap2.Pitch = 0.0;
值得注意的是,如果地图不可见,则在转换过程中会得到null。如果可能的话,您可能需要考虑使用半径。下面是一个例子:

//Declare radius variable
double radius;
try
{
    //Set pitch to zoom level so ConvertViewpointToGeoCoordinate does not return null in 8.0
    RMap2.Pitch = RMap2.ZoomLevel;
    //Gets the distance between the center and the center left edge in meters
    radius = RMap2.Center.GetDistanceTo(radarMap.ConvertViewportPointToGeoCoordinate(new Point(0, 200)));
    //Converts meters to nautical miles
    radius = radius * 0.00053996;
}
//If your map is not visible, ConvertViewpointToGeoCoordinate will return null, and you better have a good backup plan
//Since this usually only happens when the app is first loading, I have determined the distance for when zoom level is 7.0 (using the code above, I just set the zoom level to 7.0, and then set a breakpoint on the last line to check the radius)
//You could do other things here like change it to visible
catch { RMap2.ZoomLevel = 7.0; radius = 98.766450549077661; }
//Resets pitch to 0.0 so the map looks 2D
//These lines of code execute so quickly the user will not see the pitch change
RMap2.Pitch = 0.0;
希望这有帮助

GeoCoordinate topLeft = new GeoCoordinate();
GeoCoordinate bottomRight = new GeoCoordinate();
try
{
    //Set pitch to zoom level so ConvertViewpointToGeoCoordinate does not return null in 8.0
    RMap2.Pitch = RMap2.ZoomLevel;
    topLeft = RMap2.ConvertViewportPointToGeoCoordinate(new Point(0, 0));
    bottomRight = RMap2.ConvertViewportPointToGeoCoordinate(new Point(400, 400));
}
catch {  }
//Resets pitch to 0.0 so the map looks 2D
//These lines of code execute so quickly the user will not see the pitch change
RMap2.Pitch = 0.0;
//Declare radius variable
double radius;
try
{
    //Set pitch to zoom level so ConvertViewpointToGeoCoordinate does not return null in 8.0
    RMap2.Pitch = RMap2.ZoomLevel;
    //Gets the distance between the center and the center left edge in meters
    radius = RMap2.Center.GetDistanceTo(radarMap.ConvertViewportPointToGeoCoordinate(new Point(0, 200)));
    //Converts meters to nautical miles
    radius = radius * 0.00053996;
}
//If your map is not visible, ConvertViewpointToGeoCoordinate will return null, and you better have a good backup plan
//Since this usually only happens when the app is first loading, I have determined the distance for when zoom level is 7.0 (using the code above, I just set the zoom level to 7.0, and then set a breakpoint on the last line to check the radius)
//You could do other things here like change it to visible
catch { RMap2.ZoomLevel = 7.0; radius = 98.766450549077661; }
//Resets pitch to 0.0 so the map looks 2D
//These lines of code execute so quickly the user will not see the pitch change
RMap2.Pitch = 0.0;