我第一次尝试在Windows手机上安装应用程序。对于我的第一个真实项目,我虽然会在手机上显示地图,我的中心是我自己的GPS坐标。不幸的是,我遇到了可以想象的每一个问题,谷歌第一次对我有帮助。现在每当我在手机上打开应用程序时,它都会显示一个空白屏幕。这是我的xaml代码。
<phone:PhoneApplicationPage
x:Class="GPSTest.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:m="clr-namespace:Microsoft.Phone.Maps.Controls;assembly=Microsoft.Phone.Maps"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True">
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<m:Map x:Name="MainMap"
Grid.Row="0"
Height="748"
Margin="10,10,10,0"
VerticalAlignment="Top"
ZoomLevel="14" Grid.RowSpan="2"/>
</Grid>
</phone:PhoneApplicationPage
这是我后面代码中的代码:xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using GPSTest.Resources;
using Microsoft.Phone.Maps.Controls;
using System.Device.Location;
using System.Threading;
using Windows.Devices.Geolocation;
namespace GPSTest
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
OneShotLocation();
}
private async void OneShotLocation()
{
Geolocator geolocator = new Geolocator();
geolocator.DesiredAccuracyInMeters = 50;
try
{
Geoposition geoposition = await geolocator.GetGeopositionAsync(
maximumAge: TimeSpan.FromMinutes(5),
timeout: TimeSpan.FromSeconds(10)
);
Double DLat = Convert.ToDouble(geoposition.Coordinate.Latitude.ToString("0.00"));
Double DLong = Convert.ToDouble(geoposition.Coordinate.Longitude.ToString("0.00"));
MainMap.Center.Latitude = DLat;
MainMap.Center.Longitude = DLong;
}
我听说我需要添加对bing地图的引用,Bing Maps for C#,C ++或Visual Basic,但是不能添加它,因为它没有显示在我的引用列表中。关于获得钥匙的事情。我去了一个,但不能把它放在CredentialsProvider =因为它说它不需要。
他们似乎有很多过时的代码,这可能是问题所在。提前谢谢你,我真的很困惑。
答案 0 :(得分:1)
如果你在Windows Phone 8中,这里可以实现诺基亚地图,因此不需要密钥
现在您的currnet位置使用此代码
Geolocator geoLocator = new Geolocator();
Geoposition geoPosition = await geoLocator.GetGeopositionAsync();
Geocoordinate myGeocoordinate = geoPosition.Coordinate;
GeoCoordinate myGeoCoordinate = CoordinateConverter.ConvertGeoCoOrdinate(myGeocoordinate);
// mapWithMyLocation.Center = myGeoCoordinate;
mapWithMyLocation.SetView(myGeoCoordinate , 10, MapAnimationKind.Parabolic);
由于这些新地图,Geocoordinate和GeoCoordinate存在差异。所以你必须转换它,以便使用这个转换器方法
public static GeoCoordinate ConvertGeoCoOrdinate(Geocoordinate geoCooridinate)
{
return new GeoCoordinate(
geoCooridinate.Latitude,
geoCooridinate.Longitude,
geoCooridinate.Altitude ?? double.NaN,
geoCooridinate.Accuracy,
geoCooridinate.AltitudeAccuracy ?? double.NaN,
geoCooridinate.Speed ?? double.NaN,
geoCooridinate.Heading ?? double.NaN);
}
这很容易不是吗? : - )