问题
Using this query api how to get the nearby places in to our mapcontrol in windows phone 8.1. When I placed the code from the above link it shows the 404 error (i.e resource not found).
I got bing maps key. But how to place the access id. How the data source are named. Please help me.
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();
Is the above url layout is correct. How to display them in our map control.
回答1:
The following code listing uses NAVTEQEUDataSource for searching nearby. You can take it for example
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;
}
}
How it works you can read more at this post. The code listing uses some other util classes to handle response so I think you should read that post directly.
回答2:
Taking a look into your account it doesn't look like there is any data source that can be accessed at
http://spatial.virtualearth.net/REST/v1/data/20181f26d9e94c81acdf9496133d4f23/petrolbunk/petrolbunk
Have you created a data source? If you have, in the Bing Maps portal, go to Data Sources -> View Data source information. Find the data source you want to access and copy the complete URL (you don't need to break it up into pieces i.e. accessId, data source name, entity name).
If you want to access one of the point of interest data sources in Bing Maps, then take a look at the NAVTEQNA data source: https://msdn.microsoft.com/en-us/library/hh478192.aspx
来源:https://stackoverflow.com/questions/33212447/how-to-get-nearby-locations-using-query-api-in-windows-phone-8-1