Issue encountered with Google Maps: Invalid format detected. The input does not appear to be a valid LatLng or LatLngLiteral object, possibly stemming from a problem with the '

My task involves importing addresses from a Google spreadsheet and then placing them on a Google map. The latitude and longitude for each location are stored in a variable which I use to create markers by looping through all the entries. Everything seems to be working fine with the connection between the Google Spreadsheet and the website, except that only the first entry is being displayed. This leads me to believe that there may be an issue with my loop.

Initially, I suspected that the problem lied within the values of

_location.latitude/_location.longitude
. To troubleshoot this, I attempted setting the .value but it turns out this was not the source of the issue.

The loop can be found within the _setLocations function and from my research, it appears that either var _bounds or _bounds.extend is causing the problem.

_createGoogleMap: function(_mapID){

          var _this = this;

          var _locations = [];

          var _sheetUrl = 'https://sheets.googleapis.com/v4/spreadsheets/xxxxxxxxxxxxxxxxxxx/values/Sheet1!A2:U?key=xxxxxxxxxxxxxxxxxxxxxx';

          var _map = new google.maps.Map(document.getElementById(_mapID), this._mapProp);

          $.getJSON(_sheetUrl, function(data) {
            $(data.values).each(function() {
              var _location = {};
                _location.latitude = parseFloat(this[8]);
                _location.longitude = parseFloat(this[9]);
                _locations.push(_location);
            });

            _this._setLocations(_map, _locations);

          });
        },


_setLocations: function(_map, _locations) {

          var _this = this;

          var _bounds = new google.maps.LatLngBounds();

          var _infowindow = new google.maps.InfoWindow({
            content: "Content String"
          });
          for (var i = 0; i < _locations.length; i++) {
            var _new_marker = _this._createMarker(_map, _locations[i], _infowindow);

            _bounds.extend(_new_marker._position);
          }
          _map.fitBounds(_bounds);

        },

Before entering the loop, when I use 'console.log(_locations);', I can see all the addresses being printed. However, after the loop ends, I no longer see any output.

I would greatly appreciate any assistance with resolving this issue.

Answer №1

Consider utilizing a correct LatLng object for better accuracy

   user_position = new google.maps.LatLng(_coordinates[i].latitude, _coordinates[i].longitude) ;
   var _marker = _this._generateMarker(_map, _user_position, _infowindow);

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

EBUSY: Unable to access resource due to being busy or locked, unable to retrieve information from 'C:hiberfil.sys'

I am running into an issue while attempting to publish an npm package. The error message I keep receiving is causing me some trouble. Does anyone have any suggestions on how I can resolve this? Your help would be greatly appreciated! Thank you in advance ...

Nested JSON in AngularJS filter usage

I am experiencing issues while attempting to filter my table using the provided JSON object. The filtering works for some key values, but fails when the json is nested. I believe I am making a mistake somewhere. For reference, here is a fiddle demonstrati ...

Implementing a feature in React where the active class is applied only to the next element upon clicking

I'm just starting out with React and working on a custom menu bar project. The Mobile menu includes 2 dropdown submenus, which I want to toggle open and close by clicking an arrow. Currently, the arrows are functioning, but when I click on one arrow, ...

When iterating through a loop, the final value in an array is often overlooked

I have been attempting to iterate through an array to determine if any of the values, when compared to all other values in the array using the modulo operation, do not return a 0. Essentially, this process should only return the prime numbers in the array ...

Sending Parsed Information to Callback for Flexible Use

Is there a way to pass the value of coins, or even better, currency to my callback function so I can freely use the parsed JSON data in other functions? function fetchJSON(path, callback) { var jsonReq = new XMLHttpRequest(); jsonReq.onreadystatechang ...

Chart Subscription Established but Alerts Not Being Dispatched

After successfully creating my GraphServiceClient subscription on my user, I initially received a positive response. The JSON data for the subscription included information such as the resource, change type, client state, notification URL, expiration date/ ...

Obtain a result value from MySQL in Node.js

I need help retrieving a value from a select SQL query in Node.js. When I try to return the value, it comes back as undefined. I understand that it's an asynchronous function, but I'm struggling with how to handle it. I even tried assigning it to ...

What is the most efficient way to find the sum of duplicates in an array based on two different properties and then return the

var data = [ { "amount": 270, "xlabel": "25-31/10", "datestatus": "past", "color": "#E74C3C", "y": 270, "date": "2020-10-31T00:00:00Z", "entityId": 1, "entityName": "Lenovo HK", "bankName": "BNP Paribas Bank", "b ...

Ways to configure several resolve statements in Angular's UI-router?

Is there a way to prevent the page from loading before the data is ready, avoiding the view updating while the page is still loading? I have been successful in using a 'resolve' in UI-router to run a method and fetch data before loading the page ...

What could be the reason for the lack of data updates in my component?

I am having an issue with a simple component in my code. Here is the code snippet: <my-comp :item="item"></my-comp> // in script components: { MyComp }, data : { item: 'hello' } After I assign a value to the data item, it on ...

Steps to retrieve information from this JSON object

Express js is being used to fetch data from mysql and it is sent using res.json(theData). On the client side, the data is received and displayed in the console like this: { "data":[ { "PlazaID":1, "PlazaName":"fff", "P ...

Icon for TypeScript absent from npm package listings

Recently, I created a package and uploaded it to the npm repository. The package was displayed with an icon labeled "ts" on the website. https://i.stack.imgur.com/LoY1x.png The accompanying package.json showcased the inclusion of the "ts" icon - https:// ...

Looking for a way to update template variables in copy using grunt?

I am currently utilizing load-grunt-config along with grunt-contrib-copy. My objective is to have the copy task replace certain template tags using the 'process' option. I understand that replacing template tags is feasible based on the grunt-co ...

Is a TypeError thrown when a callback is given for synchronous globbing?

Here is the detailed error encountered during execution: # node app.js throw new TypeError('callback provided to sync glob') ^ TypeError: callback provided to sync glob at glob (C:\Users\z\Documents\node_modu ...

Is there a keen eye out there that can help me pinpoint the mistake in this SVG/Javascript function?

I have created a series of SVG circles that are meant to alternate in color between blue and red with each click. However, I am experiencing some inconsistency in the behavior. In my local environment, the color doesn't change to red until the second ...

Utilize JSON to structure the format of the string

Contained within this file named subtitles.ass, you'll notice I define {font_size} and {sentence[0}. It is clear that I intend to customize them with my input data. [Script Info] ; Script generated by FFmpeg/Lavc57.107.100 ScriptType: v4.00+ PlayResX ...

Tips for transferring a reference to a variable, rather than its value, to a method in VueJS

Within my template, there is this code snippet: <input @input="myMethod(myVariableName)" /> Following that, I have the myMethod function: myMethod(variablePassed) { console.log(variablePassed) } Upon execution, I receive the value of th ...

"Angular Ionic combination for displaying lists with customized headers and footers on cards

My issue is fairly straightforward - I am looking to create a list card with item array from my controller. However, I am struggling with how to structure my data in the HTML. The list card should have a header, content, and footer. I have attempted variou ...

Ways to dynamically update the value of an object property within reactJS state

In the scenario where a component holds state like so: this.state = { enabled: { one: false, two: false, three: false } } What is the proper way to utilize this.setState() in order to set the value of a dynamic property? An attempt such ...

A guide on accessing the content of two p tags in React by utilizing the useState hook in ReactJs

I am currently working on retrieving the values of two p tags simultaneously to send those values to the backend. This is my useState declaration: const [isProposal, setIsProposal] = useState({ contractorName: "", newProposal: "" }); c ...