What is the process of incorporating a Map feature (Google or Bing) into a Windows platform using PhoneGap?

I successfully completed my Phonegap app for iOS and Android, but now I am facing a nightmare with the Windows platform.

I need to integrate a map in my app. For iOS and Android, I used mapsplugin, but unfortunately it does not support the Windows platform.

So, for Windows, I attempted to use Maps JavaScript API. However, it only displays a blank screen on Windows devices while working perfectly on iOS and Android (I manually tested it on both).

After numerous failed attempts, I have decided to switch to Bing Maps for the Windows platform. I tried using Bing Map Dev Center and copied the entire HTML code into my index.html file. Unfortunately, I encountered an error stating "Microsoft is undefined" at :

map = new Microsoft.Maps.Map(document.getElementById('myMap'), {credentials: 'Your Bing Maps Key'});

I suspect the issue lies in my index.html file not being able to load the necessary JS source below:

<script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>

I have spent countless days trying to resolve this issue, but to no avail. Any assistance would be greatly appreciated.

Answer №1

Upon examination, I have identified a potential issue related to the new security protocols in Cordova applications. By default, Cordova restricts calls to external resources. The Bing Maps services operate through specific domains, typically with one or more subdomains.

  • https://*.bing.com
  • https://*.virtualearth.net

To enhance security, it is recommended to utilize HTTPS over HTTP. These domains can be whitelisted as per the documentation provided here:

For Windows 10 targeting, open the config.xml file within your Cordova project. After locating the line <access origin="*" /> near the top of the file, include the following two additional lines:

<access origin="*.bing.com" subdomains="true" />
<access origin="*.virtualearth.net" subdomains="true" />

If after building your project you encounter issues, verify that your app targets Windows 10 specifically. Check the preference property in the config.xml file to ensure the target version is set to 10.0 like so:

<preference name="windows-target-version" value="10.0" />

After deploying your app, testing on a Windows 10 device should yield positive results. Keep in mind there are known performance challenges with touch controls on Windows 10 phones at present, which our team is actively addressing.

Tip: If using Visual Studio and encountering deployment errors for a Windows Phone, confirm that the build configuration's target platform is set to Windows Phone (Universal).

Initially, troubleshooting revealed differing methods for whitelisting domains based on the target device. Subsequently, the process was adapted for Android devices as well. On Android, domain whitelisting involves configuring content security policy via a meta tag. By default, Cordova includes this meta tag:

<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">

Attempting to whitelist mentioned domains initially led to network trace blockages. Notably, Bing Maps necessitates only one URL specification for accessing map control code but utilizes a modular framework requiring dynamic loading of additional resources using inline script tags. Security settings concerning this behavior can be configured within the meta tag.

Consequently, updating the security meta tag to the following empowered the loading of JavaScript and CSS files from designated domains while allowing necessary additional resource retrieval:

<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval' 'unsafe-inline' https://*.bing.com https://*.virtualearth.net; style-src 'self' 'unsafe-inline' https://*.bing.com https://*.virtualearth.net; media-src *" >

Combining these adjustments, below is a straightforward code sample for creating a full-screen map within a Cordova application:

<!DOCTYPE html>
<html>
    <head>
        <title></title>

        <meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval' 'unsafe-inline' https://*.bing.com https://*.virtualearth.net; style-src 'self' 'unsafe-inline' https://*.bing.com https://*.virtualearth.net; media-src *" >

        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">

        <script type='text/javascript' src='https://www.bing.com/api/maps/mapcontrol?callback=GetMap' async defer></script>
        <script>
            var map;

            function GetMap() {
                map = new Microsoft.Maps.Map('#myMap', {
                    credentials: 'Your Bing Maps Key'
                });
            }
        </script>
        <style>
            body, html{
                padding:0;
                margin:0;
            }
        </style>
    </head>
    <body>
        <div id="myMap"></div>
    </body>
</html>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Switching Iframe Source with Javascript Button State

I'm currently working on creating a set of toggle buttons for a website that will change the content of an iframe depending on the combination of buttons selected. Let's say I want to display a product that is available in: - Three colors: Red, ...

Associate the callback function with a directive that does not have an isolated scope

Ensuring the correct context when binding a callback function to a directive is crucial. When working with an isolated scope, this task is easily accomplished. <bar-foo callback="mycontroller.callback()"></bar-foo> The directive code: ... ...

What is the best way to achieve a complete vertical rotation around an object using OrbitControls?

I want the rotation to continuously go around the object, but I'm having trouble setting the minPolarAngle and maxPolarAngle values (Setting them to (+-)Infinity causes the rotation to stop). Is it possible for the min and max PolarAngles in OrbitCon ...

looping through the elements in a collection using a for-in loop

Issue with IE 11 Console Chrome Console Behavior When changing the word 'item' to 'anotherItem' in the loop like so: var obj = { id1: 'item 1', id2: 'item 2', id3: 'item 3' }; for (anothe ...

Performing a modulo operation within a v-for loop

I'm showcasing divs in a loop and I need to assign classes based on the loop index. My goal is to have index 0 and 1 with the class col-6, then indexes 2,3,4 with the class col-4, followed by index 5 and 6 having the class col-6, and so forth. This w ...

The markers from KML exported from My Maps are not showing up on the Google Maps JavaScript API

I have a map on Google My Maps that I want to showcase through the Google Maps JavaScript API. This way, I can easily merge multiple maps into one and add paths/markers without needing to code it all manually. Test out the map I'm using by clicking t ...

Developing a custom JavaScript function to iterate through a group of html elements

In my mission to create a function that loops through a set of HTML elements and gathers their values, I aim to then utilize those values to produce an HTML textarea. Thus far, I've established a series of HTML input boxes and a JavaScript function f ...

Extract specific elements from an array using Mongoose's $slice operator while still maintaining the

Currently, my task is to retrieve the total number of items in my News object and return a portion of those items as objects. While I have successfully implemented the $slice operator in my query, I am struggling to determine the original array size of the ...

ID is Enclosed in Quotation Marks by JSON.Stringify

My JSON file is being modified by using JSON.stringify and JSON.parse based on updates from an online database. While everything is functioning correctly, there is an issue where numbers are being converted to strings with quotes in the JSON file. For in ...

using the information from the child array within a v-if condition

I'm struggling to extract data from a child array and utilize it in my v-if condition. Below are my data and code. Any assistance would be appreciated, even if it's just pointers to the right documentation. <div class='post' v-for= ...

Exploring the Diversity of Forms with Ajax and JQuery

$(document).ready(function () { $("#addrow").click(function () { var newRow = '<tr><td><input type="text" class="item_code form-control" placeholder="Item Code" name="item_code[]"></td><td><input type="text" ...

This is the command that includes the line "test": "tsc && concurrently "karma start karma.conf.js""

When running npm run test with the line "test": "tsc && concurrently \"karma start karma.conf.js\"" in my package.json, I encounter the error message 'Error: no test specified'. Can someone guide me on how to resolve this issue? ...

What is the best method for combining numerous tiles within a level in Kaboom JS?

Creating a level in kaboomJS with a extensive tile map collisions can sometimes result in slower performance. I'm exploring options to optimize this process, such as potentially merging multiple tiles together so that a whole row of blocks could funct ...

Initiate timers simultaneously on various devices

I'm working on developing a web application that allows one user to initiate a timer, and all other users' timers (across various devices) will sync up to start simultaneously. Currently, I am utilizing node.js and websockets for this purpose. Wh ...

Tips for properly applying the CSS display property to images

I have a piece of HTML code that includes an image of Rapunzel. The image has the style attribute set to display inline, but when I try to retrieve the display property using JavaScript, it always returns 'block' instead. I have tried using both ...

`Troubleshooting Issue: Autocomplete feature in Jquery Codeigniter not functioning

Having an issue with autocomplete in my codeigniter project. When I input text into the field, a dropdown appears but no values are shown. It looks like this: Screenshot The error displayed in the console is: Screenshoot Below is the relevant code: Mode ...

Extract information from a JSON string using a foreach loop to handle multiple occurrences of the same data type

I am working with a JSON object that I need to parse in order to retrieve specific data. The structure is as follows: "id": "5019b4b40cd8a056446b8eb4", "checkItemStates": [ { "idCheckItem": "xxxxxxxx", "state": "complete" }, { "idCheckItem ...

Adding a thousand separator feature to a React Mui TextField

I'm having trouble with my TextField in MUI. I have successfully separated the digits, but now I want to add a thousand separator to the value. Here is my code snippet: <TextField size='small' label ...

Discover the CSS auto height value using JavaScript

Is there a way to utilize JavaScript in determining the value set for auto height in CSS? My development stack includes Grails and jQuery. For instance, consider the following CSS: .tool-preview { height: auto; } ...

Tips for deactivating trackball rotation events and triggering a custom rotation event while adjusting the rotation speed within the custom event

In an attempt to disable the trackball control rotate event and trigger a custom rotate event, I have encountered some challenges. While setting controls.enableRotate = false; works for OrbitControl, it does not completely disable the trackball control r ...