question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

map.addEventListener(plugin.google.maps.event.MAP_READY, function(){}) doesn't work in the success callback of http request

See original GitHub issue

Mine is an angular based cordova app where I initialize the map view and wait for it in a controller. It works fine, when I do this:

app.controller('eventDataCTRL', ['$scope', '$location', 'eventFactory', '$http', function($scope, $location, eventFactory, $http){
  $scope.eventFactory = eventFactory;
  var div = document.getElementById("map_canvas");
  // Initialize the map view
  map = plugin.google.maps.Map.getMap(div);
  // Wait until the map is ready status.
  map.addEventListener(plugin.google.maps.event.MAP_READY, onMapReady([42.3601, -71.0589]));
  $http({
    method: 'POST',
    url: "https://xyz.com/",
    headers: {
      'Content-Type': 'application/json'
    },
    data: JSON.stringify({uri:eventFactory.event_url[0]})
  }).then(function successCallback(response) {

    }, function errorCallback(response) {
  });

But what I want is send coordinates which I get from this endpoint, or more specifically for any location (lat, long) I want. so this doesn’t work:

app.controller('eventDataCTRL', ['$scope', '$location', 'eventFactory', '$http', function($scope, $location, eventFactory, $http){
  $scope.eventFactory = eventFactory;
  var div = document.getElementById("map_canvas");
  // Initialize the map view
  map = plugin.google.maps.Map.getMap(div);
  // Wait until the map is ready status.
 
  $http({
    method: 'POST',
    url: "https://xyz.com/",
    headers: {
      'Content-Type': 'application/json'
    },
    data: JSON.stringify({uri:eventFactory.event_url[0]})
  }).then(function successCallback(response) {
     map.addEventListener(plugin.google.maps.event.MAP_READY, onMapReady([42.3601, -71.0589]));
    }, function errorCallback(response) {
  });

For the sake of privacy I replaced the http request url with a random url. Any help would be greatly appreciated.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:16 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
kanalasumantcommented, Oct 25, 2017

I will certainly donate to this wonderful and simple to use plugin you created.

0reactions
wf9a5m75commented, Oct 25, 2017

Thank you for your donation!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Events | Maps JavaScript API - Google Developers
The below sample will show you what events are triggered by the google.maps.Map as you interact with the map. For a complete list...
Read more >
Jquery google map plugin, adding event listeners
AddEvenListener is used because the events are not handled in a standard Javascript/jQuery way. You'll need to read through the Google Maps API...
Read more >
__tcfapi function - addEventListener, removeEventListener ...
The addEventListener command registers a listener for a callback function with the CMP. The listener's callback function is triggered when ...
Read more >
[Google Maps Library] Click Event | OutSystems
First you need to get the map object, and then add the listener to that map. Having that its just setting the callbacks...
Read more >
Getting Started with the Google Maps JavaScript API - Part III
Adding an event listener to your map is much like using the addEventListener() method on a DOM element. In Part II of this...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found