Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6359169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:28:58+00:00 2026-05-24T23:28:58+00:00

I’m working with the google maps API and trying to stringify an array of

  • 0

I’m working with the google maps API and trying to stringify an array of points, which each have a latitude and longitude. What I want to do is stringify the data and store it in a database so that it can be retrieved later. The problem is that, because of the way google maps stores and uses data, the result of JSON.stringify is strangely random at times. For example, sometimes the data looks like this:

[{"Na":35.99663,"Oa":-78.94982},
 {"Na":35.996370000000006,"Oa":-78.94914},
 {"Na":35.99595,"Oa":-78.94833000000001},...]

And sometimes the exact same data looks like this:

[{"Ia":35.99663,"Ja":-78.94982},
 {"Ia":35.996370000000006,"Ja":-78.94914},
 {"Ia":35.99595,"Ja":-78.94833000000001},...]

In fact I’ve seen about ten different variations. This causes a lot of problems when I store the stringified data in the database and retrieve it, because I never know which format to expect. What I want to do is replace the keys so that the data looks more like this:

[{"lat":35.99663,"lon":-78.94982},
 {"lat":35.996370000000006,"lon":-78.94914},
 {"lat":35.99595,"lon":-78.94833000000001},...]

I’ve already written code to figure out which random letters google maps is using. With that information, I want to replace each occurrence of those random letters with “lat” or “lon”. I hope to use a replacer method like so…

function formatData(data) {
    //data is an object that I want to stringify

    //this testPoint and testString help us figure out which letters google is using this time around
    var testPoint = new google.maps.LatLng(23,45);
    var testString = JSON.stringify(testPoint);
    var strangeLat = testString.substring(2,4); //this is a random two character string which represents latitude in the stringified data
    var strangeLon = testString.substring(10,12); //this is a random two character string which represents longitude in the stringified data

    //stringify the data and replace all occurences of the random letters with lat and lon
    var formattedData = JSON.stringify(data, function(key,value) {
        //do something here to replace the keys
    });

    return formattedData;     
}

I know how to replace values with the replacer function, but I can’t figure out how to replace keys. I searched around and found a few similar cases online: JSON.stringify, change the case of the key and Replace keys JSON in javascript . However, I had trouble understanding them and was unable to come up with a solution to fit my needs.

Thanks in advance for any help or suggestions!


Update!

Thanks all. I was able to come up with a solution using a combination of your suggestions. Here’s what it looks like:

function formatData(data) {
    //data is an array of many LatLng objects

    newData = [];

    for(var i = 0; i < data.length; i++) {
        var obj = new Object();
        obj['lat'] = data[i].lat();
        obj['lon'] = data[i].lng();
        newData.push(obj);
    }

    return JSON.stringify(newData);     
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T23:28:59+00:00Added an answer on May 24, 2026 at 11:28 pm

    Method below will do what you want

    var ar = [{"Ia":35.99663,"Ja":-78.94982},{"Ia":35.996370000000006,"Ja":-78.94914},{"Ia":35.99595,"Ja":-78.94833000000001}];
    
    var newAr = [];
    for(var i = 0; i < ar.length; i++)
    {
       var obj = new Object();
       var u = 0;
       for(var x in ar[i])
       { 
    
            if(u == 0)
             obj['lat'] = ar[i][x];
            else
             obj['lon'] = ar[i][x];
          u++;
        }
        newAr.push(obj);
    }
    alert(newAr.toSource());
    

    What I have done:
    1. I have created new array
    2. Then I have looped through ar
    3. Then I have looped through object properties from ar
    4. and I have assigned values of properties to new properties

    and that is it

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a simple page using Google Maps API 3. My first. One marker
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a French site that I want to parse, but am running into
I am trying to loop through a bunch of documents I have to put
I have a text area in my form which accepts all possible characters from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I used javascript for loading a picture on my website depending on which small

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.