【问题标题】:Is it possible to get closest city to my location using nokia maps on WP8?是否可以使用 WP8 上的诺基亚地图找到离我最近的城市?
【发布时间】:2014-02-11 16:59:52
【问题描述】:

我可以在 wp8 上获取我的当前位置。然后我尝试根据该位置使用诺基亚地图进行地理编码,但我总是得到奇怪的结果。他们都没有指向城市或类似的东西

我用来获取位置的代码:

Geolocator geolocator = new Geolocator();
geolocator.DesiredAccuracyInMeters = 50;
Geoposition position = await geolocator.GetGeopositionAsync(TimeSpan.FromMinutes(1), TimeSpan.FromSeconds(30));
MyCoordinate = new GeoCoordinate(position.Coordinate.Latitude, position.Coordinate.Longitude);

然后是地理编码:

var geoQuery = new GeocodeQuery();
geoQuery.SearchTerm = "put city result of reverseGeoding for MyCoordinate";
geoQuery.QueryCompleted += geoQuery_QueryCompleted;
geoQuery.GeoCoordinate = geo;
geoQuery.QueryAsync();

下一步:

void geoQuery_QueryCompleted(object sender, QueryCompletedEventArgs<IList<MapLocation>> e)
{
    if (e.Error == null && e.Result.Count > 0)
    {
    }
}

e.Result 数组可以包含指向地球上某个地方的地理坐标,但并不总是靠近 MyCoordinate。

是否可以在 WP8 上使用诺基亚地图找到离我最近的城市?

【问题讨论】:

    标签: windows-phone-8 maps reverse-geocoding here-api


    【解决方案1】:

    您可以使用ReverseGeocodeQuery class 从地理坐标获取和寻址:

    ReverseGeocodeQuery query = new ReverseGeocodeQuery();
    query.GeoCoordinate = myGeoCoordinate;
    query.QueryCompleted += query_QueryCompleted;
    query.QueryAsync();
    

    你得到一个MapAddress类型的对象,它有很多属性,包括城市:

    void query_QueryCompleted(object sender, QueryCompletedEventArgs<System.Collections.Generic.IList<MapLocation>> e)
    {
        if (e.Error != null)
            return;
    
        MapAddress address = e.Result[0].Information.Address;
        string city = address.City;
    }
    

    为了使用这个 api,你必须在 WMAppManifest.xml 文件中指定ID_CAP_MAP 能力。

    【讨论】:

      猜你喜欢
      • 2012-04-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-27
      相关资源
      最近更新 更多