Bing Maps for Windows UWP apps


Adding images with tapped event


Hi there,
I have completed my first Windows Phone 8.1 app with a default map control. That map had images on it, that used Binding in XAML. That way I could set the location and URL of the images via a data model. I also had a Tapped event so that I could do something
when you touched the images.
I am now trying to achieve the same on Windows 8.1, but I believe I'm stuck with the Bing Maps API... I can't figure out how to add an image via XML. I did make a maplayer, and add all my items to that, with a picture. But the problem is that I can't seem
to get a tapped event for that? Is that even possible?
Also, when I move/zoom the map, my images are drifting across the map, and don't stay in place. They have a position, and Ive set the anchor point. What's up with that?
Oh, and last but not least: Why the hell do I have to create a seperate ARM, x86 and x64 package? It's tripling my build time and just seems wasteful...
There are a few different ways to do this. I usually do most of my mapping work in code as it compiles smaller and also runs a lot faster when you have large data sets. Here is an example using pure XAML:
<Page
x:Class="App1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App1"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:m="using:Bing.Maps"
xmlns:f="using:Windows.Foundation"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<m:Map Name="MyMap" Credentials="YOUR_BING_MAPS_KEY">
<m:Map.Children>
<m:MapLayer Name="DataLayer">
<Image Source="Assets/SmallLogo.scale-100.png" Tapped="Image_Tapped" Width="30" Height="30" Margin="-15,-15,0,0">
<m:MapLayer.Position>
<m:Location Latitude="45" Longitude="-110"/>
</m:MapLayer.Position>
</Image>
</m:MapLayer>
</m:Map.Children>
</m:Map>
</Grid>
</Page>
In stead of using a position anchor I prefer to use negative margins. I write a lot of cross platform code and the negative margin approach works on all of the Bing Maps controls, where as the position anchor value has different names/usage in some of the
other controls. You may also find this blog post on correctly anchoring pushpins useful:
https://rbrundritt.wordpress.com/2014/10/02/correcting-anchoring-pushpins-to-the-map/
For the Tapped event, simply add it to the image.
As for your last question, the Bing Maps control is a Native control, which means that it's written in C++. As such it makes use of the C++ runtime (you should notice a reference to that gets automatically added to your project when you reference
Bing Maps). The C++ runtime can only be compiled against a single CPU type at a time and doesn't have an Any CPU option. You will find that if you use any library in C# or VB that makes use of the C++ runtime that you will run into this same
CPU build restriction.
Since you are new to the Bing Maps Windows Store SDK you might find my free ebook useful:
https://rbrundritt.wordpress.com/my-book/ It shows how to do pretty much everything you could want to do with the map control. You can also find all the source code to all the samples here:
https://code.msdn.microsoft.com/Location-Intelligence-for-1c691d0ehttp://rbrundritt.wordpress.com
There are a few different ways to do this. I usually do most of my mapping work in code as it compiles smaller and also runs a lot faster when you have large data sets. Here is an example using pure XAML:
<Page
x:Class="App1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App1"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:m="using:Bing.Maps"
xmlns:f="using:Windows.Foundation"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<m:Map Name="MyMap" Credentials="YOUR_BING_MAPS_KEY">
<m:Map.Children>
<m:MapLayer Name="DataLayer">
<Image Source="Assets/SmallLogo.scale-100.png" Tapped="Image_Tapped" Width="30" Height="30" Margin="-15,-15,0,0">
<m:MapLayer.Position>
<m:Location Latitude="45" Longitude="-110"/>
</m:MapLayer.Position>
</Image>
</m:MapLayer>
</m:Map.Children>
</m:Map>
</Grid>
</Page>
In stead of using a position anchor I prefer to use negative margins. I write a lot of cross platform code and the negative margin approach works on all of the Bing Maps controls, where as the position anchor value has different names/usage in some of the
other controls. You may also find this blog post on correctly anchoring pushpins useful:
https://rbrundritt.wordpress.com/2014/10/02/correcting-anchoring-pushpins-to-the-map/
For the Tapped event, simply add it to the image.
As for your last question, the Bing Maps control is a Native control, which means that it's written in C++. As such it makes use of the C++ runtime (you should notice a reference to that gets automatically added to your project when you reference
Bing Maps). The C++ runtime can only be compiled against a single CPU type at a time and doesn't have an Any CPU option. You will find that if you use any library in C# or VB that makes use of the C++ runtime that you will run into this same
CPU build restriction.
Since you are new to the Bing Maps Windows Store SDK you might find my free ebook useful:
https://rbrundritt.wordpress.com/my-book/ It shows how to do pretty much everything you could want to do with the map control. You can also find all the source code to all the samples here:
https://code.msdn.microsoft.com/Location-Intelligence-for-1c691d0ehttp://rbrundritt.wordpress.com
Thanks a lot for your help!
For some weird reason, my problem with images moving is solved after I've put it in the store and tried on my PC and Surface RT. But on my machine on which I build the app, it still moves around while debugging. Is this some kind of issue for debugging or
something?
Not that I know of. Haven't had anyone else report any issue like this that wasn't caused by incorrect anchor positioning. Only thing I could think of would be a video card issue as that has been known to cause some weird behavior with the emulator
for Windows 8.http://rbrundritt.wordpress.com

Related Links

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++
Binding to LocationCollection: What does the following mean?: "White Space is missing."
Binding and Converting List of Coordinates for MapPolyline
Bing Maps pushpin on Windows 8.1 ARM
Does Bing Maps SDK for Windows Store apps support SSL?
pushpins disappear

Categories

MSDN
Using Forums
Game Development
Microsoft Office for D...
Apps for Office and Sh...
Microsoft Robotics
Windows Embedded Compact
Windows Server
Microsoft Research
Project Server
Microsoft Atlas API: D...
Microsoft Azure
Archived Forums I-L
Archived Forums M
In-App Advertising (Ad...
Windows Phone Preview ...
Software Entwicklung f...
MSDN and TechNet Profi...
Visual F#
Test Tools in Visual S...
Dev Center App
Windows Desktop Sideba...
Windows Hardware Testi...
Developing Apps for Of...
SharePoint 2013 - Search
SharePoint Legacy Vers...
Azure Multi-Factor Aut...
Azure BizTalk Services
Azure Notification Hubs
Cognitive Services
Azure SQL Data Warehouse
Azure DevTest Labs
Azure IoT Hub
Azure Stack
Team Foundation Server...
Team Foundation Server...
Team Foundation Server...
BizTalk ESB Toolkit
LINQ to SQL
XML, System.Xml, MSXML...
Code Contracts
The Forum of Sho
Microsoft Translator U...
Small Basic
SyncFx - General [Read...
SyncFx – Microsoft Syn...
SQL Server Integration...
SQL Server XML
SQL Service Broker
SQL Server Setup & Upg...
SQL Server High Availa...
SQL Server Compact
SQL Server Express
SQL Server Application...
SQL Server Manageability
Standard 7: Tools
Standard 7: Servicing ...
Windows Forms Sample A...
Script Junkie Discussion
WebsitePanel - Support
WebsitePanel - Enterpr...
The Samsung Windows De...
Microsoft Unified Comm...
Microsoft Lync Persist...
Microsoft Unified Comm...
Microsoft Lync Client ...
Silverlight Controls a...
Visual Studio & Silver...
MVVM / ViewModel Patte...
PivotViewer Control wi...
Silverlight Video and ...
Visual Studio Report C...
Windows Performance To...
Retired SharePoint Bus...
Retired SharePoint Soc...
Project Online General...
.NET Framework 4: Wind...
.NET Platform Architec...
Axum Incubation Project
Feedback for Visual Ba...
Game Technologies: Aud...
Game Technologies: Dir...
Getting Started With V...
HealthVault Data Types
Innovate on Office
Microsoft ESP Platform...
Monitor, Alert and Aut...
Office Live Small Busi...
Office Live Small Busi...
Parallel Computing Gen...
patterns & practices: ...
Popfly Game Creator
Project Codename:  Jasper
Search Server: Known B...
Silverlight (formerly ...
Security for Azure
Software Transactional...
Team Foundation Server...
Visual Basic Express E...
Visual Basic Interop a...
Visual Studio Async CTP
Visual Studio 2008 (Pr...
Visual Studio Code Ana...
Visual Studio Guidance...
Visual Studio UI Autom...
Windows Live Data Deve...
Tools for Windows Stor...
XML in Visual Studio a...
XNA Game Studio Express
Ad Revenue, Payout & T...
SQL Server 2016 Preview
Microsoft Partner Cent...
Skype Web SDK
Maps In Windows - APIs

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile