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

  • Home
  • SEARCH
  • 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 9092985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:58:29+00:00 2026-06-16T22:58:29+00:00

From the google maps API documentation I have got this working: var flightPlanCoordinates =

  • 0

From the google maps API documentation I have got this working:

var flightPlanCoordinates = [
    new google.maps.LatLng(37.772323, -122.214897),
    new google.maps.LatLng(21.291982, -157.821856),
    new google.maps.LatLng(-18.142599, 178.431),
    new google.maps.LatLng(-27.46758, 153.027892)
  ];

what ive tried to do is replicate this piece of code with my own loop so I can use previously stored co-ords, like so:

var output;
$.getJSON('DisplayMap.php',  function(data) {
        var output = "[ ";
        for (var i in data.b) {
            output+= "new google.maps.LatLng" + "(" + data.b[i].Ya + ", " + data.b[i].Za + ")," + " ";
        }

       output+= "]";
        document.getElementById("placeholder").innerHTML=output;
    alert(output);
  });


                output+= "]";

Ive checked the output and it looks exactly as I want it to. however, when I substitute it in like this is doesnt work:

var flightPlanCoordinates = output;
  • 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-06-16T22:58:30+00:00Added an answer on June 16, 2026 at 10:58 pm

    In your new code you are building a string instead of an array. You should have something like this instead:

    var output = [];
    
    for (var i in data.b) {
        output.push(new google.maps.LatLng(data.b[i].Ya, data.b[i].Za));
    }
    

    In addition, I am slightly confused by the fact that you create a variable named output both inside and outside of getJSON. Keep in mind that getJSON is asynchronous and you will not be able to use the variable from within getJSON immediately after it is called.

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

Sidebar

Related Questions

This is a code sample taken from the Google Maps API developer's guide. I'm
I have created an infobox using google maps api v3 and infoBox from the
I tried to 'imitate' the code from this map: https://google-developers.appspot.com/maps/documentation/javascript/examples/geocoding-simple only changing Syney to
I have a simple object that get's geocoding data from the Google Maps API
I am using http://code.google.com/apis/maps/documentation/geocoding/ api from google to get geolocation based on address. I
I am trying to create a polyline from google maps v3 api. I know
It seems that licensing terms would prevent us from using Google Maps API in
I've recently been upgrading the pages for my website from the Google Maps API
I'm trying to create a custom javascript class that inherits from google.maps.Map (V3 API).
I am trying to migrate from v2 to v3 in google maps API and

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.