The issue of AngularJs leaflet directive map not displaying correctly on mobile devices when integrated with the ionic

Recently, I delved into using Ionic and incorporated Angular Leaflet Directive for geolocation display.

Everything seemed fine on desktop, but I hit a roadblock that I can't seem to overcome.

On mobile devices, the paths do not show up and the map remains gray.

https://i.sstatic.net/c8EHf.png

My Controller

.controller('ShowCtrl', function($scope, $stateParams, $ionicLoading, $timeout, $http, leafletData) {

  $ionicLoading.show({template: 'Downloading...'});

  $scope.center = {};
  $scope.paths = {};
  $scope.markers = {};
  $scope.defaults = {};
  $scope.map = {};

    $http({
    method: 'GET',
    url: 'https://api.foursquare.com/v2/venues/'+$stateParams.id,
     params: {
          'client_id'     : 'xxx',
          'client_secret' : 'xxx',
          'v'             : '20130815',
        }
  }).then(function successCallback(data) {
      $timeout(function () {

         $scope.place = data.data.response.venue;
         $scope.title = data.data.response.venue.name;

            angular.extend($scope, {
                center: {
                    lat: $scope.lat,
                    lng:  $scope.long,
                    zoom: 12
                },
                paths: {
                    p1: {
                        color: '#ff612f',
                        weight: 5,
                        latlngs: [
                            { lat: data.data.response.venue.location.lat, lng: data.data.response.venue.location.lng },
                            { lat: $scope.lat, lng: $scope.long }
                        ],
                    }
                },
                markers: {
                    destination: {
                        lat: data.data.response.venue.location.lat,
                        lng: data.data.response.venue.location.lng,
                        message: data.data.response.venue.name,
                        focus: true,
                        draggable: false,
                        icon: {
                            iconUrl: 'lib/leaflet/dist/images/marker-icon2.png',
                        }
                    },
                    mylocation: {
                        lat: $scope.lat,
                        lng:  $scope.long,
                        icon: {
                            iconUrl: 'lib/leaflet/dist/images/marker-icon.png',
                        }
                    }
                },
                defaults: {
                    scrollWheelZoom: false,
                    zoomControl:false 
                }
            });
          $ionicLoading.hide();
     }, 2000);
    });
});

Map

<leaflet id="map" center="center" paths="paths"  markers="markers" defaults="defaults"></leaflet>

Could someone lend me a hand with this issue?

Answer №1

What version of Cordova are you currently utilizing?

A recent update now requires the utilization of cordova-plugin-whitelist. Consequently, you must explicitly permit each HTTP request you initiate.

Since Leaflet tiles are sourced from the internet, it is essential to grant permission for them as well.

The conventional and recommended meta for this purpose is:

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

Incorporating this line within the head section of your HTML code should lead to improved performance.

Answer №2

One solution to the issue was to ensure that the tileLayer is initialized before making the ajax call.

This can be achieved by implementing the following:

$scope.defaults = { zoomControl: false, layerControl: false, tileLayer: 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'};

$http({
    method: 'GET',
    url: 'https://api.foursquare.com/v2/venues/'+$stateParams.id,
     params: {
          'client_id'     : 'xxx',
          'client_secret' : 'xxx',
          'v'             : '20130815',
        }
  }).then(function successCallback(data) {
      $timeout(function () {

         $scope.place = data.data.response.venue;
         $scope.title = data.data.response.venue.name;

            angular.extend($scope, {
                markers: {
                    destination: {
                        lat: data.data.response.venue.location.lat,
                        lng: data.data.response.venue.location.lng,
                        message: data.data.response.venue.name,
                        focus: true,
                        draggable: false,
                        icon: {
                            iconUrl: 'lib/leaflet/dist/images/marker-icon2.png',
                        }
                    },
                    mylocation: {
                        lat: $scope.lat,
                        lng:  $scope.long,
                        icon: {
                            iconUrl: 'lib/leaflet/dist/images/marker-icon.png',
                        }
                    }
                }
            });
          $ionicLoading.hide();
     }, 2000);
    });

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

How to remove an event listener that was added within a function in JavaScript?

I am encountering an issue while trying to remove an event listener that was created inside a function. Oddly enough, it works perfectly when I move the event listener outside of the function. See the example below: <body> <div id='myDiv&apo ...

Are there any alternatives to Python's Format Specification Mini-Language available in JavaScript or Vue?

Currently, I am involved in a Django project where data is being sent through vector tiles to a Vue(tify) frontend. Due to this specific architecture, it is not feasible to execute Python on Django model instances as intended. The vector tiles are being cr ...

Tips for sending list values as function arguments within AngularJS

HTML code When I click the button in the second controller, the "itemBought List" is rendering with empty strings for name and quantity, even though there is data in itemToBuy.itemList. It seems like the datas for name and quantity are not being passed i ...

Why is it that I am getting undefined when I try to map over a populated array within this.state?

After a user logs in to my app, the home component is rendered and in its componentDidMount method, I fetch the documents associated with the logged-in user. The fetch call successfully retrieves the data, which is then stored in this.state using a this.se ...

Is there a tutorial for JavaScript with Selenium WebDriver?

I've recently embarked on the journey of writing tests with Selenium WebDriver and JavaScript. However, I'm facing a roadblock in finding a comprehensive tutorial that covers element locators, commands, verification commands for elements, clickin ...

What are the steps to creating a multi-level horizontal dropdown menu with subcategories and sub-subcategories?

Does anyone know how to create a horizontal dropdown menu like the one on the Parkour Generations website, but with a sub-sub menu that appears horizontally when hovering over the submenu? In Parkour Generations, if you navigate to classes -> outdoor, ...

JavaScript does not recognize jsPDF

After importing the jsPDF library, I attempted to export to PDF but encountered a JavaScript error stating that jsPDF is not defined. I tried various solutions from similar posts but none of them seemed to work for me. You can find the fiddle here: https ...

Consolidate information from various APIs into one centralized location

I am curious to know how one can consolidate data from multiple APIs into a single API. My goal is to retrieve the results from all four res.data endpoints and display them at /coingeckotest address. Even though I am able to see the desired result in the ...

stop angularjs loop in the view section

Is there a method to exclude the last value in ng-options="sport.sport_id as sport.name for sport in sports" {"sport_id":1,"name":"a"},{"sport_id":2,"b":"c"},{"sport_id":3,"name":"d "},{"sport_id":"4","name":"e"}] I want to hide the 'e' value ...

Tips for ensuring the server only responds after receiving a message from the client in a UDP Pinger system using sockets

I am in the process of developing a UDP pinger application. The objective is for the client to send a message (Ping) and receive pong back 10 times. However, the challenge lies in sending the messages one at a time instead of all together simultaneously. T ...

Is it possible for JavaScript to access and read a local file from a web page hosted locally

I am interested in using html, css, and javascript to develop a user interface for configuring a simulation. This interface will be used to generate a visualization of the simulation and an output parameters file based on multiple input files. It is impor ...

React - assigning a value to an input using JavaScript does not fire the 'onChange' event

In my React application with version 15.4.2, I am facing an issue where updating the value of a text input field using JavaScript does not trigger the associated onChange event listener. Despite the content being correctly updated, the handler is not being ...

Extracting information from Javascript on an HTML webpage

The text snippet provided is a segment of an HTML page. I am looking to extract the data but unsure about the most effective method to do so. JSON would be ideal, however, I am uncertain if this content can be converted into JSON format. Is Regular Expre ...

Tips for transforming code with the use of the then block in javascript, react, and cypress

In my code snippet below, I have several nested 'then' clauses. This code is used to test my JavaScript and React code with Cypress. { export const waitForItems = (retries, nrItems) => { cy.apiGetItems().then(items => { if(items ...

Enhancing the appearance of hyperlinks within a UIWebView

Currently, I am using a UIWebView to display content that includes clickable links. The UIWebView automatically highlights and underlines these links, but I'm wondering if there is a way to customize their styling. Specifically, I'd like to chang ...

Utilizing AJAX in Cordova to Generate Dynamic JavaScript Charts from JSON Data

Exploring the world of Cordova, I have delved into utilizing canvas Js for visualizing data in chart format. Following a helpful tutorial, I created a Json file and inserted the specified data as instructed, following each step diligently. The outcome matc ...

Retrieve the HTML content from the compiled template

function ($scope,$compile) { $scope.word="Habrahabra" var template = $compile("<p>{ { name } }</p>") var templ = template({name: "Ivan"}) document.getElementById("status").innerHTML =templ } I am currently facing an issue where in the ...

Issue encountered while sending a jQuery error to the server?

Utilizing jQuery ajax POST throughout my application, here's an example of an ajax post. The content type is determined by the data variable. Content Type could be either application/x-www-form-urlencoded; charset=UTF-8 or application/json; charset=ut ...

Ensure that the WebRTC video stream content is centered when displaying a tall video on a wide screen

Currently, I am encountering an issue while making a webrtc video call between a mobile device in portrait mode and a laptop. The streams from the mobile and the laptop have different aspect ratios, causing challenges when trying to display the video fulls ...

Mastering the Art of Incorporating jQuery, JavaScript and CSS References into Bootstrap with ASP.NET WebForms

Hey there, I'm currently working on a personal project as a beginner in Bootstrap. My main challenge for the past two days has been trying to integrate a dateTimePicker and number Incrementer using Bootstrap techniques. Despite my efforts in researchi ...