1

我正在为 WP8 创建一个应用程序,并且一直在使用 Bing 地图教程。但是我在澳大利亚没有得到任何结果。我是否需要使用完全不同的 API?geolocale包含一个字符串,例如"20.002, -150.2222"即使我将其更改为只是"California"它得到结果。我究竟做错了什么?

我试图在很多地方找到答案,但似乎找不到任何相关的东西。

         try
        {
            searchService.SearchCompleted += new EventHandler<SearchService.SearchCompletedEventArgs>(MySearchCompleted);

            SearchService.SearchRequest mySearchRequest = new SearchService.SearchRequest();
            mySearchRequest.Credentials = new SearchService.Credentials();
            mySearchRequest.Credentials.ApplicationId = "key";

            SearchService.StructuredSearchQuery ssQuery = new SearchService.StructuredSearchQuery();
            ssQuery.Keyword = "coffee";
            ssQuery.Location = geolocale;
            mySearchRequest.StructuredQuery = ssQuery;

            searchService.SearchAsync(mySearchRequest);

        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
4

2 回答 2

1

坐标 20.002,-150.2222 位于太平洋中部。此外,必应地图 SOAP 服务是旧的遗留 API。应使用必应空间数据服务。 http://msdn.microsoft.com/en-us/library/ff701734.aspx http://rbrundritt.wordpress.com/2012/01/17/dynamically-updating-data-in-bing-maps-v7/

于 2013-11-18T19:57:07.733 回答
0

要在 WP8 中使用 Bing 空间数据服务,首先从该项目复制 Response、ResultSet 和 Result 类:http ://code.msdn.microsoft.com/Augmented-Reality-with-bcb17045/sourcecode?fileId=85735&pathId=1819751232

然后,您可以使用以下代码生成搜索查询。

string baseURL; 

//Switch between the NAVTEQ POI data sets for NA and EU based on where the user is. 
if (Longitude < -30) 
{ 
    //Use the NAVTEQ NA data source: http://msdn.microsoft.com/en-us/library/hh478192.aspx 
    baseURL = "http://spatial.virtualearth.net/REST/v1/data/f22876ec257b474b82fe2ffcb8393150/NavteqNA/NavteqPOIs"; 
} 
else 
{ 
    //Use the NAVTEQ EU data source: http://msdn.microsoft.com/en-us/library/hh478193.aspx 
    baseURL = "http://spatial.virtualearth.net/REST/v1/data/c2ae584bbccc4916a0acf75d1e6947b4/NavteqEU/NavteqPOIs"; 
} 

//Search radius should be converted from meters to KM.
string poiRequest = string.Format("{0}?spatialFilter=nearby({1:N5},{2:N5},{3:N2})&$format=json&$top={4}&key={5}", 
    baseURL, Latitude, Longitude, SearchRadius / 1000, MaxResultsPerQuery, BingMapsKey); 

您将需要一种方法来将此查询传递给并序列化结果。使用以下内容:

private void GetResponse(Uri uri, Action<Response> callback) 
{ 
    System.Net.WebClient client = new System.Net.WebClient(); 
    client.OpenReadCompleted += (s, a) => 
    { 
        try 
        { 
            using (var stream = a.Result) 
            { 
                DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Response)); 

                if (callback != null) 
                { 
                    callback(ser.ReadObject(stream) as Response); 
                } 
            } 
        } 
        catch (Exception e) 
        { 
            if (callback != null) 
            { 
                callback(null); 
            } 
        } 
    }; 
    client.OpenReadAsync(uri); 
} 

最后,您需要调用 GetResponse 方法来进行如下查询:

GetResponse(new Uri(poiRequest), (response) => 
{ 
    if (response != null && 
        response.ResultSet != null && 
        response.ResultSet.Results != null && 
        response.ResultSet.Results.Length > 0) 
    { 
        //Do something with the results
    }
});
于 2014-02-24T09:12:34.913 回答