Windows phone 8 地理定位器异常
Windows phone 8 Geolocator Exception
您好,我是 WP 开发的新手。我想找到用户当前的邮政编码或邮政编码。所以我有以下代码。问题是这一行 d.zip = position.CivicAddress.PostalCode;
总是给出未设置为对象实例的对象引用 exception.But 我能够很好地获得纬度和经度。我也试过 position.CivicAddresss.City 但仍然是同样的异常。请帮忙。
async void Button_Click_1(object sender, RoutedEventArgs e)
{
Data d = new Data();
Geolocator locator = new Geolocator();
try
{
Geoposition position = await locator.GetGeopositionAsync();
d.zip = position.CivicAddress.PostalCode;
d.Latitude = position.Coordinate.Latitude;
d.Longitude = position.Coordinate.Longitude;
MessageBox.Show(d.zip);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
public class Data
{
public string zip { get; set; }
public double Latitude { get; set; }
public double Longitude { get; set; }
}
我认为 GeoPosition.CivicAddress 已被弃用。您需要使用 MapLocationFinder 来获取地址信息。
async void Button_Click_1(object sender, RoutedEventArgs e)
{
Data d = new Data();
Geolocator locator = new Geolocator();
try
{
Geoposition position = await locator.GetGeopositionAsync();
// Get address data with MapLocationFinder
var result = await MapLocationFinder.FindLocationsAtAsync(position.Coordinate.Point);
if (result.Status == MapLocationFinderStatus.Success)
{
var address = result.Locations[0].Address;
var zip = address.PostCode;
d.zip = zip;
}
// These are deprecated as well.
// Use position.Coordinate.Point.Position.Latitude and
// position.Coordinate.Point.Position.Longitude
d.Latitude = position.Coordinate.Latitude;
d.Longitude = position.Coordinate.Longitude;
MessageBox.Show(d.zip);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
public class Data
{
public string zip { get; set; }
public double Latitude { get; set; }
public double Longitude { get; set; }
}
您好,我是 WP 开发的新手。我想找到用户当前的邮政编码或邮政编码。所以我有以下代码。问题是这一行 d.zip = position.CivicAddress.PostalCode;
总是给出未设置为对象实例的对象引用 exception.But 我能够很好地获得纬度和经度。我也试过 position.CivicAddresss.City 但仍然是同样的异常。请帮忙。
async void Button_Click_1(object sender, RoutedEventArgs e)
{
Data d = new Data();
Geolocator locator = new Geolocator();
try
{
Geoposition position = await locator.GetGeopositionAsync();
d.zip = position.CivicAddress.PostalCode;
d.Latitude = position.Coordinate.Latitude;
d.Longitude = position.Coordinate.Longitude;
MessageBox.Show(d.zip);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
public class Data
{
public string zip { get; set; }
public double Latitude { get; set; }
public double Longitude { get; set; }
}
我认为 GeoPosition.CivicAddress 已被弃用。您需要使用 MapLocationFinder 来获取地址信息。
async void Button_Click_1(object sender, RoutedEventArgs e)
{
Data d = new Data();
Geolocator locator = new Geolocator();
try
{
Geoposition position = await locator.GetGeopositionAsync();
// Get address data with MapLocationFinder
var result = await MapLocationFinder.FindLocationsAtAsync(position.Coordinate.Point);
if (result.Status == MapLocationFinderStatus.Success)
{
var address = result.Locations[0].Address;
var zip = address.PostCode;
d.zip = zip;
}
// These are deprecated as well.
// Use position.Coordinate.Point.Position.Latitude and
// position.Coordinate.Point.Position.Longitude
d.Latitude = position.Coordinate.Latitude;
d.Longitude = position.Coordinate.Longitude;
MessageBox.Show(d.zip);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
public class Data
{
public string zip { get; set; }
public double Latitude { get; set; }
public double Longitude { get; set; }
}