c# 怎么获取 平板电脑GPS数据
现在手里有一个lenovo miix2型号的平板,win8系统,现在想通过GPS定位获取相应的坐标信息,求大神帮助。
[解决办法]
Geolocator geoloc = new Geolocator();
Geoposition position = await geoloc.GetGeopositionAsync();//h获得地理坐标
HttpClient httpClient = new HttpClient();
HttpResponseMessage httpResult = await httpClient.GetAsync(String.Format("http://maps.google.com/maps/api/geocode/xml?latlng={0},{1}&language=zh-CN&sensor=false", position.Coordinate.Latitude, position.Coordinate.Longitude));
var resss = await httpResult.Content.ReadAsStringAsync();
XmlDocument xml = new XmlDocument();
xml.LoadXml(resss);
var nr = xml.SelectNodes("GeocodeResponse").First();
var v = nr.SelectNodes("result").OrderBy(d => 1).Skip(3).Take(1).ToList().First();
var t = v.SelectNodes("formatted_address").First().InnerText;
GeoCoordinateWatcher watcher;
private void StartButton_Click(object sender, RoutedEventArgs e)
{
if (watcher == null)
{
//GeoPositionAccuracy.High定义定位的精度水平,Hight表示高
watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High);
//表示定位更新频率,即设定门限值,频率高则耗电高,因为它随时需要定位新的方位
watcher.MovementThreshold = 20;
//状态改变事件,如数据改变,服务停止等
watcher.StatusChanged + = new EventHandler<GeoPositionStatusChangedEventArgs>(watcher_StatusChanged);
//位置改变事件,如经度,纬度,海拔等
watcher.PositionChanged + = new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(watcher_PositionChanged);
watcher.Start();
}
}
void watcher_PositionChanged(object sender,
GeoPositionChangedEventArgs<GeoCoordinate> e)
{
Dispatcher.BeginInvoke(() =>
{
//获取纬度坐标
this.LatitudeTextBox.Text = e.Position.Location.Latitude.ToString();
//获取经度坐标
this.LongitudeTextBox.Text = e.Position.Location.Longitude.ToString();
});
}
void watcher_StatusChanged(object sender, GeoPositionStatusChangedEventArgs e)
{
Dispatcher.BeginInvoke(() =>
{
StatusTextBox.Text = e.Status.ToString();
});
}