Bing Maps for Windows UWP apps


Data binding in Metro UI and multiple locations ?


Hi ,
I'm creating a Metro UI C# app.
I have managed to add the bing map control in my app and also run a query to get results according to a location .
But this is the point where I got stuck.
I tried to bind a collection of objects in my map but it doesn't work.
So my first question goes How can I bind a collection of objects in my Xaml ?
And my second question goes to how to display multiple results in my map ?
Here is some of my code
<Grid.Resources>
<CollectionViewSource x:Name="LocationList"/>
<DataTemplate x:Key="LogoTemplate1">
<Maps:Pushpin>
<Maps:MapLayer.Position>
<Maps:Location Latitude="{Binding Latitude}" Longitude="{Binding Longitude}" ></Maps:Location>
</Maps:MapLayer.Position>
</Maps:Pushpin>
</DataTemplate>
</Grid.Resources>
<Maps:Map x:Name="Map" Grid.Row="2" VerticalAlignment="Top" Credentials="xxxxxx">
<Maps:Map.Children>
<Maps:MapItemsControl x:Name="ListOfItems"
ItemsSource="{Binding Source={StaticResource LocationList}}"
ItemTemplate="{StaticResource LogoTemplate1}">
</Maps:MapItemsControl>
</Maps:Map.Children>
</Maps:Map>
private async Task<Response> GetResponse(Uri uri)
{
System.Net.Http.HttpClient client = new System.Net.Http.HttpClient();
var response = await client.GetAsync(uri);
using (var stream = await response.Content.ReadAsStreamAsync())
{
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Response));
return ser.ReadObject(stream) as Response;
}
}
string query = "my address";
Uri geocodeRequest = new Uri(string.Format("http://dev.virtualearth.net/REST/v1/Locations?q={0}&key={1}", query, sessionKey));
//Make a request and get the response
Response r = await GetResponse(geocodeRequest);
if (r.StatusCode == 200)
{
//how am I suppose to get the data ?
}
and how am I suppose to refresh the Map with the new layout ?
Appreciate any help you could give me.
Location class in my example is in Bing Maps namespace (Bing.Maps.Location). Your Location class does not contain Latitude and Longitude properties so binding is not working. In your example, REST server probably return point
information so you can assign these values to Bing.Maps.Location object as below.
locations.Add(new Bing.Maps.Location(location.Point.Coordinates[0], location.Point.Coordinates[1]));
To bind with data in the response, iterate each location in the response and insert these to list object. Then assign the list object to CollectionViewSource defined in xaml. It will look something like below.
if (r.StatusCode == 200)
{
List<Location> locations = new List<Location>();
// iterate through each location in response and add to the locations list above.
// after the loop, assign the list object to CollectionViewSource.
LocationList.Source = locations;
Hi ,
I have this in my code
private void ProcessResponse(Response locationsResponse)
{
int locNum = locationsResponse.ResourceSets[0].Resources.Length;
List<Location> locations = new List<Location>();
for (int i = 0; i < locNum; i++)
{
Location location = (Location)locationsResponse.ResourceSets[0].Resources[i];
if (location.Confidence == "High")
{
locations.add(location);
}
}
this.LocationList.Source = locations;
}
But nothing.
Am I doing something wrong ?
Location class in my example is in Bing Maps namespace (Bing.Maps.Location). Your Location class does not contain Latitude and Longitude properties so binding is not working. In your example, REST server probably return point
information so you can assign these values to Bing.Maps.Location object as below.
locations.Add(new Bing.Maps.Location(location.Point.Coordinates[0], location.Point.Coordinates[1]));
 It was returning the point. You are correct. I missed that one.
thank you.

Related Links

Search Bing Maps What can I do in Korean?
Why is it that the Bing Map control has a much lower resolution than the Website?
Openstreetmap layer
MapPolyline has no Tag Property or can not be inherited
windows 8.1 bing map control issue
Find Mexican reasturants near my location
Setting Units and Updating Ellipses when User Zooms
Lang Issue with Bing Maps Ajax Control for HTML5/JS
Progress Ring over Bing Map
Windows Store App: MapPolygon: What happened to Opacity?
bing map
Could not find SDK "Bing.Maps.Xaml
Speed in Calculating Coordinates
Dashed line for polygons
Bing Maps Infobox Pins stay on top
error c3668 in using bingmap in vs2013c++

Categories

MSDN
Using Forums
JScript and Scripting
SQL Server
Feedback and Discussions
Samsung PC
Archived Forums A-B
Archived Forums I-L
Archived Forums V
Archived Forums W
Archived Forums X-Z
Kinect for Windows SDKs
Microsoft R
Announcements for all ...
Suggestions and Feedba...
MSDN and TechNet Profi...
Visual C#
C++ Standards, Extensi...
Visual Studio General ...
Visual Studio Setup an...
Dev Center App
XboxLiveDevelopment
Developing Windows Des...
DirectShow Development
Windows Desktop Sideba...
Excel for Developers
SharePoint 2013 - Setu...
SharePoint 2010 - Deve...
Azure Mobile Apps
Azure Notification Hubs
Azure Logic Apps
Azure Service Fabric
Cognitive Services
Azure Disk Encryption
Azure Database for MySQL
Windows Workflow Found...
Claims based access pl...
Visual Studio Visualiz...
LINQ to SQL
XML, System.Xml, MSXML...
The Forum of Sho
TPL Dataflow
Scripting
Microsoft Translator H...
Microsoft Robotics - C...
Microsoft Robotics - S...
SQL Server SMO/DMO
SQL Server XML
SQL Server Documentation
SQL Server Compact
Getting started with S...
Database Mirroring
SQL Server Express
SQL Server Migration
SQL Server In-Memory T...
SQL Server 2012 Setup ...
SQL Server 2012 Spatia...
SQL Server 2012 Master...
Windows Forms General
Windows Forms Data Con...
Windows Server 2008 Ap...
CRM
Orchard –Discussions
App Linking
WebsitePanel - Support
WebsitePanel - Develop...
Bing Maps Web Controls
Windows File Sharing P...
Project Server - Setup...
Microsoft Unified Comm...
Programming Silverligh...
Performance Profiling ...
PivotViewer Control wi...
Game Development with ...
Expression Studio
Connected Services Fra...
Retired SharePoint Acc...
.NET Framework 4 setup...
.NET Framework Network...
ADO.NET Entity Framewo...
Announcements about pr...
AppFabric Service and ...
Architecture Events
Archived: Software Tes...
Building Windows Store...
Building Windows Store...
Doloto
DNS and Traffic Manager
Game Technologies: XNA...
General Windows MultiP...
HealthVault Data Types
Innovate on Office
Installing and Registe...
JScript for the .NET F...
Multimap API Developme...
Office Live Small Busi...
patterns & practices: ...
Search Server: Federation
Search Server: Known B...
Silverlight (formerly ...
Security for Azure
SyncFx - Microsoft Syn...
SQL Server 2014 Report...
Tools for Windows Phon...
Visual Basic Express 2...
Visual Basic Express E...
Visual Basic Language
Visual Studio Async CTP
WCF Data Services (Pre...
Web Development in Vis...
Web Gadget Development
Working with Data and ...
Working with Data in W...
XNA Game Studio Express
Microsoft Partner Cent...

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile