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 7055505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:45:25+00:00 2026-05-28T03:45:25+00:00

I am trying to render a map with multiple polylines that are pulled from

  • 0

I am trying to render a map with multiple polylines that are pulled from an external JSON resource. Each JSON record has a number of descriptive fields as well as a field containing an array of LatLngs. The code seems to get the JSON data just fine and to parse it appropriately. I then iterate through each record mapping a polyline but for some reason I cannot get it to display on the map. This is my first time using the Google Maps API. I am probably doing something stupid but having trolled through as many examples as I could find, cannot find anything obviously wrong. All suggestions gratefully received.

The basis for the code for displaying the polylines was taken from the following example: http://code.google.com/intl/no/apis/maps/documentation/javascript/examples/polyline-simple.html

<!DOCTYPE html>
<html>
<head>
<style type="text/css">
     #map_canvas {
        width: 1024px;
        height: 700px;
      }
</style>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>

<script type="text/javascript">

function initialize(){
    var latlng = new google.maps.LatLng(0, 23);
    var myOptions = {
      zoom: 4,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

    var url = "http://webstore.thedatahub.org/stevesong/afterfibre/testdata2.json?_limit=3";
    var path = [];
        $.getJSON(url, function (data) {

            //  Parse the Linestring field into an array of LatLngs
            $.each(data.data, function(index, record) {
                line = JSON.parse(record.Linestring);

                //  Parse the array of LatLngs into Gmap points
                for(var i=0; i < line.length; i++){
                    path.push(new google.maps.LatLng(line[1],line[0]));
                }
                var polyline = new google.maps.Polyline({
                  path: path,
                  strokeColor: '#ff0000',
                  strokeOpacity: 1.0,
                  strokeWeight: 3
                });

                polyline.setMap(map);

            });

        });
    }

    // google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body onload="initialize()">
  <div id="map_canvas"></div>
</body>
</html>
  • 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-28T03:45:26+00:00Added an answer on May 28, 2026 at 3:45 am

    Thanks to Greg Mahlknecht for providing the final piece of the puzzle. In order to have each JSON record display uniquely as opposed to one giant polyline, the polyline array needs to be reinitialised AFTER each “.each” iteration. Here is the final version that finally does what I was after. Thanks Mitch and Greg.

    <!DOCTYPE html>
    <html>
    <head>
    <style type="text/css">
         #map_canvas {
            width: 1024px;
            height: 700px;
          }
    </style>
    
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
    
    <script type="text/javascript">
    
    function initialize(){
        var latlng = new google.maps.LatLng(0, 23);
        var myOptions = {
          zoom: 4,
          center: latlng,
          mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    
        var url = "http://webstore.thedatahub.org/stevesong/afterfibre/testdata2.json?_limit=5";
    
            $.getJSON(url, function (data) {
    
                //  Parse the Linestring field into an array of LatLngs
                $.each(data.data, function(index, record) {
                    var mypath = new Array();
                    line = JSON.parse(record.Linestring);
                    //  Parse the array of LatLngs into Gmap points
                    for(var i=0; i < line.length; i++){
                        //Tokenise the coordinates
                        var coords = (new String(line[i])).split(",");
                        mypath.push(new google.maps.LatLng(coords[1], coords[0]));
                    }
                    var polyline = new google.maps.Polyline({
                        path: mypath,
                        strokeColor: '#ff0000',
                        strokeOpacity: 1.0,
                        strokeWeight: 3
                    });
                    polyline.setMap(map);
                });
    
            });
        }
    
        // google.maps.event.addDomListener(window, 'load', initialize);
    </script>
    </head>
    <body onload="initialize()">
      <div id="map_canvas"></div>
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to build render the raw data from a Quake 3 .map file
I'm actually trying to render an encoded polyline obtained from the Google Map Directions
Im trying to render a django template from a database outside of djangos normal
I'm trying to render a colored cube after rendering other cubes that have textures.
I'm trying to render to a texture, then draw that texture to the screen
I'm trying to render the sortable table that's provided in Google visualization API in
In one of my Controllers, I have multiple URLs that will ultimately render in
I get the following error when trying to render foreign chars from a dict.
I'm trying to modify this code ( http://code.google.com/p/pypng/source/browse/trunk/code/texttopng ) so that it can render
Goal: To render a google map using geolocation. I am trying to implement the

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.