Converting coordinates of latitude and longitude into JSON format

I'm currently facing some challenges with organizing map waypoints, defined by latitude/longitude pairs, within a JSON array.

This is the progress I've made so far.

var llData = {};
var waypointData = {};

for (i = 0; i < routeArray.length; i++) { 
    llData['waypoint'+i] = [{"latitude" : routeArray[i].latLng.lat},{"longitude" : routeArray[i].latLng.lng}];
    waypointData.push = llData;
}

The provided code snippet is designed to cycle through multiple latitude and longitude pairs, adding them all to the waypointData array. However, the output that I am receiving is as follows:

{"push":{"waypoint1":[{"latitude":-27.47577},{"longitude":153.01693}]}}

It appears to only include the final latitudinal and longitudinal pair out of the four initially provided.

Answer №1

llData.push = waypointData;

you need to update it to:

llData.push(waypointData);

then transform var llData = {}; into an array like this:

var llData = [];

or you can also maintain it as an associative array and utilize i as its key.

llData[i]=waypointData;

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

I'm experiencing difficulties with a JavaScript slideshow in Vegas

After installing the vegas jQuery plugin to my project using npm, I encountered issues when attempting to use it according to the documentation. Despite linking the required vegas.min.js and vegas.min.css files in my HTML, the plugin doesn't appear to ...

Rearrange elements within a div by clicking a button

I want to shuffle div elements with a click of a button using a dissolve animation in HTML5. An example of what I am looking for is similar to this website When you scroll on the page, there are links such as All, Intro, Solution. Clicking on any link sh ...

Oops! We couldn't locate or access the file you're trying to import: ~bootstrap/scss/bootstrap

Following the steps outlined on getbootstrap.com, I assumed that everything would function smoothly. Unfortunately, that hasn't been the case so far. All seems well until I attempt to load the page, at which point my Express.js app throws a: [[ ...

How can a JavaScript function be triggered by Flask without relying on any requests from the client-side?

I'm in the process of setting up a GUI server using Flask. The challenge I'm facing is integrating an API that triggers a function whenever there's a change in a specific Sqlite3 database. My goal is to dynamically update a table on the HTML ...

How to Access Nested Arrays in ReactJS

As a ReactJS beginner, I've been making progress with my project. However, I've hit a roadblock that seems to be my final hurdle. Here's what I'm trying to achieve: TV Show - Simpsons Name: Bart Simpson, Gender: Male Name: Homer Simp ...

Discovering the property name of an object in Angular using $watch

Is there a way to monitor an object for changes in any of its properties, and retrieve the name of the property that changed (excluding newValue and oldValue)? Can this be accomplished? ...

Jackson is a powerful tool in JAVA that allows you to easily parse string and convert it to JSON. Here

I'm currently attempting to transform a string into JSON using Jackson. To achieve this, I've utilized the ObjectMapper().readValue() method to deserialize it into a DragDropJsonDto object. The structure of qList.getHeader() is as follows: &quo ...

What is the best way to find specific data in a JSON file using SQL commands

Looking for a way to search JSON data where in json like {"buyer_uni_no":{"info":[],"Pos":[[0,0,0,0]]}} I've attempted the following SQL queries, but they were unsuccessful. select * from test where JSON_VALUE(myjson,'$.buyer_uni_no.info&apos ...

Handling multiple patch requests using React and Redux when onBlur event occurs

Currently, I am using Redux-form for editing guest information. Whenever a field is left, the content of that field gets patched to the guest through a simple patch request and the store is updated accordingly. However, an issue arises when I use Google fo ...

Displaying JSON data on a Django template

As I worked on developing a website, I encountered an issue. The JSON data I am sending from views.py to my template is not displaying any content. data = { "philip": {"age": 20, "salary": 10000}, "jerry": {"age": 27, "salary": 30000} } names ...

What is the best way to implement JQuery in order to trigger an event in a text box whenever the user hits the "enter

Also, refrain from submitting the form if the user hits enter in THAT PARTICULAR input field. ...

Collapsed ReactJS: Techniques for compressing the Material UI TreeView following expansion

My issue involves a Material UI treeView. After expanding it, an API call is made, but the node in the treeView remains open. I have attempted to use onNodeToggle without success. Below is my code: <TreeView className={classes.root1} defaultExpandI ...

Created JSON object providing the number as a string value

I am currently facing an issue with a Vue method where it generates a JSON object from user input values before making an axios put request. The problem I'm encountering is that the JSON object generated converts numbers into strings, causing issues w ...

Transforming JSON array to List of Strings in Spring MVC applications

In my JavaScript code, I have a list of strings that I am sending to a REST based service using jQuery. Here is how I convert the JavaScript array into a JSON array: var ids = []; $("input:checked").each(function() { ids.push(this.id); }); v ...

Enhance the functionality of NodeJS core applications

I recently attempted to modify some custom functions in the FS module of NodeJS, which is an integral part of NodeJS' core modules. The specific file I targeted was fs.js, located in /usr/lib/nodejs. However, despite making changes to the code, I noti ...

Seamless animation when collapsing element using angular and css exclusively

I am attempting to incorporate a collapsible feature into my application. Rather than relying on external libraries like jQuery, I want to exclusively utilize Angular. For demonstration purposes, I have created a very basic example here: http://jsfiddle.n ...

Working with varying amounts of JSON data in REST services

I need to consume a REST web service with JSON type where the input JSON has a different number of values each time. For example: {"name":"x","age":23,"language":"java"} or {"name":"c","age":"34","language":"c++","db":"oracle"} The input JSON may vary ...

The use of event.returnValue is outdated and no longer supported. It is recommended to use the standard event.preventDefault() method instead. You may encounter

Hey there :) Currently, I am utilizing JQuery 1.9.1.js to search records using JSON. I am able to retrieve the search list locally, but when attempting to publish it on Windows Server 2008 and IIS 7, I face issues as it throws an error stating "event.ret ...

Experimenting with d3 using Node.js, JSDOM, and Jasmine

I am new to Javascript and node.js, and I want to test if a basic bar chart is being rendered in my node.js/d3 application using jasmine. Could someone provide guidance on what steps I need to take? test.js (file that needs testing): var d3 = require(&ap ...

converting rails 3 data into json format for use in javascript

Although to_json is deprecated and as_json is causing issues, I'm facing a problem. The following line functions properly, but to_json is now deprecated: new IS.Presentation(<%= raw(@course_step.step.step_presentation.step_presentation_files.map ...