Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在windows phone 8.1中使用查询API获取附近位置_C#_Visual Studio 2013_Windows Phone 8.1_Bing Maps - Fatal编程技术网

C# 如何在windows phone 8.1中使用查询API获取附近位置

C# 如何在windows phone 8.1中使用查询API获取附近位置,c#,visual-studio-2013,windows-phone-8.1,bing-maps,C#,Visual Studio 2013,Windows Phone 8.1,Bing Maps,使用此功能,您可以在windows phone 8.1中将附近的位置添加到我们的地图控件中。当我放置上面链接中的代码时,它显示404错误(即未找到资源) 我有钥匙。但是如何放置访问id以及如何命名数据源。请帮帮我 string BingMapsKey = "MY_BING_MAPS_KEY"; string DataSourceID = "20181f26d9e94c81acdf9496133d4f23"; string dataSourceName = "petrolbunk"; str

使用此功能,您可以在windows phone 8.1中将附近的位置添加到我们的地图控件中。当我放置上面链接中的代码时,它显示404错误(即未找到资源)

我有钥匙。但是如何放置访问id以及如何命名数据源。请帮帮我

string BingMapsKey = "MY_BING_MAPS_KEY";

string DataSourceID = "20181f26d9e94c81acdf9496133d4f23";


string dataSourceName = "petrolbunk";
string dataEntityName = "petrolbunk";
string accessId = DataSourceID;
string bingMapsKey = BingMapsKey;
double SearchLatitude = 47.63674;
double SearchLongitude = -122.30413;
double Radius = 3;

string requestUrl1 = string.Format("http://spatial.virtualearth.net/REST/v1/data/{0}/{1}/{2}" + "?spatialFilter=nearby({3},{4},{5})&key={6}", accessId, dataSourceName,
dataEntityName, SearchLatitude, SearchLongitude, Radius, bingMapsKey);

HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

HttpResponseMessage response = await client.GetAsync(requestUrl1);
if (response.IsSuccessStatusCode)
{
    var data = response.Content.ReadAsStringAsync();

以上url布局是否正确。如何在地图控件中显示它们。

下面的代码清单使用NAVTEQEUDataSource在附近搜索。你可以拿它为例

internal class NAVTEQEUDataSource : INAVTEQEUDataSource
{
    public async Task<IList<Geopoint>> SearchNearBy(double latitude, double longitude, double radius, int entityTypeId, int maxResult, string bingMapKey)
    {
        const string spatialBaseUrl = "http://spatial.virtualearth.net/REST/v1/data/";
        string url =
            "c2ae584bbccc4916a0acf75d1e6947b4/NavteqEU/NavteqPOIs?spatialFilter=nearby({0},{1},{2})&$filter=EntityTypeID%20eq%20'{3}'&$select=EntityID,DisplayName,Latitude,Longitude,__Distance&$top={4}&key={5}";
        HttpClient httpClient = new HttpClient { BaseAddress = new Uri(spatialBaseUrl) };
        url = string.Format(url, latitude, longitude, radius, entityTypeId, maxResult, bingMapKey);
        string response = await httpClient.GetStringAsync(url);
        XmlUtil xmlUtil = new XmlUtil(response);
        IList<XElement> properties = xmlUtil.GetElements("entry").ToList();
        IList<Geopoint> result = new List<Geopoint>();
        foreach (var property in properties)
        {
            BasicGeoposition basicGeoposition = new BasicGeoposition();

            double temp;
            if (double.TryParse(xmlUtil.GetRelativeElement(property, "content.properties.Latitude").Value, out temp))
                basicGeoposition.Latitude = temp;
            if (double.TryParse(xmlUtil.GetRelativeElement(property, "content.properties.Longitude").Value, out temp))
                basicGeoposition.Longitude = temp;
            result.Add(new Geopoint(basicGeoposition));
        }

        return result;
    }
}
内部类NAVTEQEUDataSource:INAVTEQEUDataSource
{
公共异步任务搜索(双纬度、双经度、双半径、int entityTypeId、int maxResult、string bingMapKey)
{
常量字符串spatialBaseUrl=”http://spatial.virtualearth.net/REST/v1/data/";
字符串url=
“c2ae584bbccc4916a0acf75d1e6947b4/NavteqEU/NavteqPOIs?空间过滤器=附近({0}、{1}、{2})和$filter=EntityTypeID%20eq%20'{3}'和$select=EntityID、显示名称、纬度、经度、距离和$top={4}&key={5}”;
HttpClient HttpClient=新HttpClient{BaseAddress=新Uri(spatialBaseUrl)};
url=string.Format(url、纬度、经度、半径、entityTypeId、maxResult、bingMapKey);
字符串响应=等待httpClient.GetStringAsync(url);
XmlUtil XmlUtil=新的XmlUtil(响应);
IList properties=xmlUtil.GetElements(“条目”).ToList();
IList结果=新列表();
foreach(属性中的var属性)
{
BasicGeoposition BasicGeoposition=新的BasicGeoposition();
双温;
if(double.TryParse(xmlUtil.GetRelativeElement(属性,“content.properties.Latitude”).Value,out-temp))
基本地理位置。纬度=温度;
if(double.TryParse(xmlUtil.GetRelativeElement(property,“content.properties.Longitude”).Value,out-temp))
基本地理位置。经度=温度;
结果。添加(新地质点(基本地质位置));
}
返回结果;
}
}

如何工作,你可以在这里阅读更多。代码清单使用了一些其他的util类来处理响应,所以我认为您应该直接阅读这篇文章。

查看您的帐户,看起来没有任何可以访问的数据源

您是否创建了数据源?如果有,请在Bing地图门户中,转到数据源->查看数据源信息。找到您要访问的数据源并复制完整的URL(您不需要将其拆分为多个部分,即accessId、数据源名称、实体名称)


如果您想访问Bing地图中的一个兴趣点数据源,请查看NAVTEQNA数据源:

我想要印度的附近地区(兴趣点)。如何获取数据源以使用它们查找印度的地区使用这些数据源查找印度的附近地区是可能的。如果是,如何…?否,这些数据源没有印度的数据。那么如何使用windows phone 8.1(winrt)中的Bing地图向地图控件显示印度附近的位置