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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:32:54+00:00 2026-06-13T16:32:54+00:00

I would like to add the real time dynamic to my map, by means

  • 0

I would like to add the real time dynamic to my map, by means of passing a new local geojson file about every 3 minutes. What is the best approach to do this so that it is seamless to the end-user. I am thinking ajax and or setinterval function is the answer, but I’m not sure where to begin. If anyone knows of any examples or can offer some advice. I would greatly appreciate it.

Thank you.

Here is my attempt to use AJAX. I am unable to loop over the geoJSON structure. Not sure what i ma doing wrong. AJAX and javascript is still kind of foreign to me.

   <!DOCTYPE html>
   <html>
    <head>
<p id="demo">coordinates</p>
</br>
<p id="coords">coordinates</p>
<style>
  html, body, #map_canvas { margin: 0; padding: 0; height: 100%; }
</style>
<script
  src="https://maps.googleapis.com/maps/api/js?sensor=false&   libraries=visualization,MVCObject">
</script>
<script>
    var map;



    // ajax request to load json data
    var xhr = new XMLHttpRequest();
    xhr.open('GET', 'json_template.json', true);
    xhr.onload = function() {
    //
    sector_callback(this.responseText);
    //console.log(xhr.responseText);
    };
    xhr.send();

    // function to load map into body when page loads
    function initialize() { 
        var kansas_city = new google.maps.LatLng(39.00495613,-94.64780668);
        var mapOptions = {
        zoom: 10,
        center: kansas_city,
        mapTypeId: google.maps.MapTypeId.TERRAIN
        };

    map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);
    }

    // function definition to process the geoJSON data
    function sector_callback() {
    var bounds = new google.maps.LatLngBounds();

        //console.log(xhr.responseText);
        for (var i = 0, len = features.length; i < len; i++) {
            var coords = features[i].geometry.coordinates[0];
            siteNames = features[i].properties.Name; // added for site names
            var path = [];
                    //console.log(data);
            for ( var j = 0, len2 = coords.length; j < len2; j++ ){ // pull out each set of coords and create a map object
                var pt = new google.maps.LatLng(coords[j][1], coords[j][0])
                bounds.extend(pt);
                path.push(pt);

                //path.push(new google.maps.LatLng(coords[j][1], coords[j][0]));
            }

            var polygons = new google.maps.Polygon({
            path: path,
                strokeColor: "#000000",
                strokeOpacity: 0.8,
                strokeWeight: 1,
                fillColor: "#000000",
                fillOpacity: 0.35,
            map: map
            });
            createClickablePoly(polygons, siteNames);



            google.maps.event.addListener(polygons, 'mouseover', function() {
            var currentPolygon = this;

            currentPolygon.setOptions({ // setOptions is a method and properties below
                fillOpacity: 0.45,
                fillColor: "#FF0000"
                })
            });

            google.maps.event.addListener(polygons, 'mouseout', function() {
            var currentPolygon = this;
            currentPolygon.setOptions({ 
                fillOpacity: 0.35,
                fillColor: "#000000"
                })
            }); 
        }
    }


 </script>
 </head>
 <body onload="initialize()">
   <div id="map_canvas"></div>
  <h2>AJAX</h2>
   <div id="myDiv"></div>
  </body>
</html>

geoJSON:

  {
"type": "FeatureCollection",
"features": [{
    "type": "Feature",
    "properties": {
        "Name": "1_1",
        "Description": ""
    },
    "geometry": {
        "type": "Polygon",
        "coordinates": [
            [
                [-94.963194, 39.316858],
                [-94.959670, 39.321990],
                [-94.959050, 39.321720],
                [-94.958460, 39.321400],
                [-94.957920, 39.321040],
                [-94.957420, 39.320640],
                [-94.956980, 39.320210],
                [-94.956250, 39.319270],
                [-94.955990, 39.318760],
                [-94.955780, 39.318240],
                [-94.955640, 39.317700],
                [-94.955570, 39.317160],
                [-94.955570, 39.316610],
                [-94.963194, 39.316858]
            ]
        ]
    }
}, {
    "type": "Feature",
    "properties": {
        "Name": "214_1",
        "Description": ""
    },
    "geometry": {
        "type": "Polygon",
        "coordinates": [
            [
                [-94.783917, 39.083417],
                [-94.776470, 39.084670],
                [-94.776340, 39.084140],
                [-94.776290, 39.083590],
                [-94.776300, 39.083040],
                [-94.776380, 39.082500],
                [-94.776530, 39.081960],
                [-94.777020, 39.080940],
                [-94.777360, 39.080460],
                [-94.777760, 39.080000],
                [-94.778210, 39.079570],
                [-94.778710, 39.079180],
                [-94.779260, 39.078830],
                [-94.783917, 39.083417]
            ]
        ]
     }
   }]
  }
  • 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-13T16:32:56+00:00Added an answer on June 13, 2026 at 4:32 pm

    function sector_callback() is not accepting any parameters. It should be something like function sector_callback(data). You cannot use the global variable xhr because AJAX is asynchronous.

    function sector_callback(data) {
            for (var i = 0, i < data.features.length ; i++) {
                var coords = data.features[i].geometry.coordinates[0];
                //...etc 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to add some real-time functionality to my website with node.js and
I'm a student and I would like to replicate in real time the entries
I have own project and i would like add for this class same as
I have a ListView and each item have a TextView. I would like add
I would like to add a GestureDetector to all views (view groups) of an
I would like to add a custom calculation method to a managed object (which
I would like to add roots to a VirtualTreeView http://www.delphi-gems.com/index.php/controls/virtual-treeview with a thread like
I would like to add a hash into an array using Ruby version 1.8.7:
I would like to add up the number of line changes in an SVN
I would like to add a pop effect when I hover over a SVG

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.