无法在必应地图上找到我的位置 [英] Failed to locate my location in bing map
问题描述
您好,我是Windows应用程序上的新开发人员.目前,我正在尝试定位我的位置.但是,当我尝试在模拟器上运行该应用程序时,我可以获得微软的位置,但是当我在Windows Phone上运行该应用程序时,却无法找到我的位置.任何人 能帮我吗?我从此链接 http://msdn .microsoft.com/zh-CN/library/windowsphone/develop/jj207045(v = vs.105).aspx
Hi there, im new developer on windows app. Currently i was trying to locate my location. However when i tried to run the app on emulator i able to get microsoft location but when i run the app on my windows phone i was not able to locate my location. anyone could help me out? I followed the tutorial from this link http://msdn.microsoft.com/en-US/library/windowsphone/develop/jj207045(v=vs.105).aspx
推荐答案
您可以使用它们;
You can use these;
1)
添加"System.Device";参考
Add "System.Device" Reference
2)
C#
using System.Device.Location;
VB.NET
Imports System.Device.Location
3)
将变量声明为GeoCoordinateWatcher
3)
declare a variable as GeoCoordinateWatcher
C#
GeoCoordinateWatcher gwatcher;
VB.NET
Private WithEvents gwatcher As GeoCoordinateWatcher
2)
假设单击按钮后观察者将启动
C#
Assume that the watcher will start when a button is clicked
C#
private void Button_Click_1(object sender, RoutedEventArgs e)
{
if (gwatcher == null)
{
gwatcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High);
gwatcher.MovementThreshold = 20;
gwatcher.StatusChanged += new EventHandler<GeoPositionStatusChangedEventArgs>(gwatcher_StatusChanged);
}
gwatcher.Start();
}
VB.NET
Private Sub Button_Click_1(sender As Object, e As RoutedEventArgs)
If gwatcher Is Nothing Then
gwatcher = New GeoCoordinateWatcher(GeoPositionAccuracy.High)
gwatcher.MovementThreshold = 20
End If
gwatcher.Start()
End Sub
3)
此处的观察者状态已更改; (假设我们有2个文本块,名称分别为"latitude_txt"和"longitude_txt",并且当状态更改时,我们将在其上打印输出.
And the watcher status changed here; (Assume that we have 2 textblock that names are "latitude_txt" and "longitude_txt" and when status is changed, we will print the output on these.
C#
void gwatcher_StatusChanged(object sender, GeoPositionStatusChangedEventArgs e)
{
if (e.Status == GeoPositionStatus.Ready)
{
GeoCoordinate co = gwatcher.Position.Location;
latitude_txt.Text = co.Latitude.ToString("0.000");
longitude_txt.Text = co.Longitude.ToString("0.000");
gwatcher.Stop();
}
}
VB.NET
Private Sub gwatcher_StatusChanged(sender As Object, e As GeoPositionStatusChangedEventArgs) Handles gwatcher.StatusChanged
If e.Status = GeoPositionStatus.Ready Then
Dim co As GeoCoordinate = gwatcher.Position.Location
latitude_txt.Text = co.Latitude.ToString("0.000")
longitude_txt.Text = co.Longitude.ToString("0.000")
gwatcher.Stop()
End If
End Sub
希望这可以帮助
Hope this helps
这篇关于无法在必应地图上找到我的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!