Reputation: 1438
Is there any way to include maps in UWP Windows apps written in Javascript?
The obvious options:
Thank you.
Upvotes: 0
Views: 381
Reputation: 17954
There is no built in JavaScript map API for UWP. You can however use the Bing Maps V8 map control. As you know JavaScript based Windows apps that don't use a WebView/WebBrowser restrict the use of externally hosted JavaScript files. There are two ways around this.
The first is to host your map code inside of an iframe. This works fine if your map functionality is completely contained and you don't need to programmatically make changes to the map from your main app (unlikely). UWP apps won't let you communicate between your main app and JavaScript code in an iframe.
The second is to modify how you reference the start page in your app and instead of using a local context, use a web context. To do this, open the package.appxmanifest, and add "ms-appx-web:///" before the start page value. Likely "ms-appx-web:///index.html". This will may limit your application from using some of the lower level features in JavaScript based UWP apps, like accessing the file system.
In both of these scenarios, also do the following:
One your map page, it is recommended that you add the following to the head of the page:
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
Neither of these solutions is perfect. The security in JavaScript based Windows UWP is the main limitation which many users have experienced with other externally host web based API's. The only real way around this is to host your JavaScript application in a web browser control and then add a communication layer between that and .NET code, and then use the .NET code to access the Windows specific API's, but if you go that route, you might as well use Apache Cordova which does exactly this for you.
Upvotes: 1