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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:57:06+00:00 2026-05-28T06:57:06+00:00

I am querying a PostGIS database based on where a user clicks on a

  • 0

I am querying a PostGIS database based on where a user clicks on a google map. I am then parsing the JSON response into a googleMaps infoWindow. This has been working great but I’d now like to query multiple urls and use those responses to fill in the infoWindow. Below is an example of the functions I’ve used that work great. Note: please disregard the url provided as I just made it up for this example.

var clickLoc;

function queryAct(event){
clickLoc=event.latLng;  
var clickLat=clickLoc.lat();
var clickLng=clickLoc.lng();
var loUrl = 'http://www.myspatialdataset.com/sql/?q=select%20ownercateg%20from%20stew_owners%20where%20ST_Intersects%28the_geom,%20ST_GeomFromText%28%27POINT%28'+clickLng+'%20'+clickLat+'%29%27,4326%29%29';  
if (window.XMLHttpRequest) { // Non-IE browsers
  req = new XMLHttpRequest();
  req.onreadystatechange = clickResponse;
  try {
    req.open("GET", loUrl, true);
  } catch (e) {
    alert(e);
  }
  req.send(null);
} else if (window.ActiveXObject) { // IE
  req = new ActiveXObject("Microsoft.XMLHTTP");
  if (req) {
    req.onreadystatechange = clickResponse;
    req.open("GET", loUrl, true);
    req.send();
  }
}

}

function clickResponse(){                               
    if (req.readyState == 4) { // Complete
      if (req.status == 200) { // OK response                     
          var clickPingBack = JSON.parse(req.responseText);
          var loResponse = clickPingBack;
          if (loResponse.rows.length>0)
          {
            var loResponseParsed=loResponse.rows[0].ownercateg;
            fillWithClicked(loResponseParsed);
          }
          else
          {
              var loResponseParsed=' other';
              fillWithClicked(loResponseParsed);                                                                      
          }         
      }
}
}

var infowindow = new google.maps.InfoWindow;

function fillWithClicked(loResponseParsed){ 
infowindow.setContent(loResponseParsed);
infowindow.setPosition(clickLoc);
infowindow.open(map);   
}

How could I now do this for multiple url requests and pass those responses to the same, fillWithClicked function that fills in the infoWindow?

The code below is obviously wrong but may better explain what I am trying to do i.e. multiple URLS and filling the infoWindow with the response from two url requests. This sometimes works but is totally wrong

var clickLoc;

function distQueryAct(event){
clickLoc=event.latLng;  
var clickLat=clickLoc.lat();
var clickLng=clickLoc.lng();
var distUrl = 'http://www.myspatialdataset.com/sql/?q=select%20district%20from%20mt_elk%20where%20ST_Intersects%28the_geom,%20ST_GeomFromText%28%27POINT%28'+clickLng+'%20'+clickLat+'%29%27,4326%29%29';  
if (window.XMLHttpRequest) { // Non-IE browsers
  distReq = new XMLHttpRequest();
  distReq.onreadystatechange = loQueryAct(clickLoc);
  try {
    distReq.open("GET", distUrl, true);
  } catch (e) {
    alert(e);
  }
  distReq.send(null);
} else if (window.ActiveXObject) { // IE
  distReq = new ActiveXObject("Microsoft.XMLHTTP");
  if (distReq) {
    distReq.onreadystatechange = loQueryAct(clickLoc);
    distReq.open("GET", distUrl, true);
    distReq.send();
  }
}
}

function loQueryAct(clickLoc){
var clickLat=clickLoc.lat();
var clickLng=clickLoc.lng();
var loUrl = 'http://www.myspatialdataset.com/sql/?q=select%20ownercateg%20from%20stew_owners%20where%20ST_Intersects%28the_geom,%20ST_GeomFromText%28%27POINT%28'+clickLng+'%20'+clickLat+'%29%27,4326%29%29';  
if (window.XMLHttpRequest) { // Non-IE browsers
  loReq = new XMLHttpRequest();
  loReq.onreadystatechange = distClickResponse;
  try {
    loReq.open("GET", loUrl, true);
  } catch (e) {
    alert(e);
  }
  loReq.send(null);
} else if (window.ActiveXObject) { // IE
  loReq = new ActiveXObject("Microsoft.XMLHTTP");
  if (loReq) {
    loReq.onreadystatechange = distClickResponse;
    loReq.open("GET", loUrl, true);
    loReq.send();
  }
}
}

function distClickResponse(){                               
    if (distReq.readyState == 4 && loReq.readyState == 4) { // Complete
      if (distReq.status == 200 && loReq.status == 200) { // OK response                      
          var distPingBack = JSON.parse(distReq.responseText);
          var distResponse = distPingBack;
          var loPingBack = JSON.parse(loReq.responseText);
          var loResponse = loPingBack;
          if (distResponse.rows.length>0)
          {
            var distResponseParsed=distResponse.rows[0].district;
          }
          else
          {
              var distResponseParsed=' other';
          } 
           if (loResponse.rows.length>0)
          {
            var loResponseParsed=loResponse.rows[0].ownercateg;             
          }
          else
          {
              var loResponseParsed=' other';                                                      
          }           
      }
      distFillWithClicked(loResponseParsed,distResponseParsed);                           
}
}

var infowindow = new google.maps.InfoWindow;

function distFillWithClicked(distResponseParsed,loResponseParsed){  
infowindow.setContent(distResponseParsed+loResponseParsed);
infowindow.setPosition(clickLoc);
infowindow.open(map);   
}
  • 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-28T06:57:06+00:00Added an answer on May 28, 2026 at 6:57 am

    I figured it out. Using getJSON instead of XMLHttpRequest was the key. I know this could be cleaner but it does work.

    var clickLoc;
    
    function queryAct(event){
    clickLoc=event.latLng;  
    var clickLat=clickLoc.lat();
    var clickLng=clickLoc.lng();    
    var toFillArray=Array();
    var loUrl='http://www.mypostgis.com/sql/?q=select%20ownercateg%20from%20stew_owners%20where%20ST_Intersects%28the_geom,%20ST_GeomFromText%28%27POINT%28'+clickLng+'%20'+clickLat+'%29%27,4326%29%29'; 
    var distUrl='http://www.mypostgis.com/sql/?q=select%20district%20from%20mt_elk%20where%20ST_Intersects%28the_geom,%20ST_GeomFromText%28%27POINT%28'+clickLng+'%20'+clickLat+'%29%27,4326%29%29';   
    $.getJSON(loUrl,function(tmpLoDat){     
        if (tmpLoDat.rows.length>0)
        {
            var tempCat=tmpLoDat.rows[0].ownercateg;        
            toFillArray.push(tempCat);
        }
        else
        {
            var tempCat='other';
            toFillArray.push(tempCat);  
        }       
        otherFunction(toFillArray,distUrl);
        })                  
    }
    
    function otherFunction(toFillArray,distUrl){
    $.getJSON(distUrl,function(tmpDistDat){
        if (tmpDistDat.rows.length>0)
        {
            var tempDist=tmpDistDat.rows[0].district;
            toFillArray.push(tempDist);
        }
        else
        {
            var tempDist='Other';
            toFillArray.push(tempDist);
        }
        fillWithClicked(toFillArray);
        })      
    }
    
    
    
    var infowindow = new google.maps.InfoWindow;
    
    function fillWithClicked(toFillArray){ 
    infowindow.setContent(toFillArray[0]+toFillArray[1]);
    infowindow.setPosition(clickLoc);
    infowindow.open(map);   
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Querying my database to get a user so I can log them out, but
When querying a database from Node, how does one pass the HTTP response object
After querying from database, I fill the result into dataset, suppose there are 10
AM querying an access database from vb6 using the following query INSERT INTO stock([i_name],[ref],[qty],[supplier_id])
I am querying the database, inserting the resultant values in an array then manipulating
When querying with LDAP against our Active Directory structure to look up user accounts,
i'm querying a database like this: SELECT * from Log WHERE cookieId IN (select
When querying the database with: @robots = Robot.all(:condition => [:a => 'b'], :limit =>
I'm querying a database and some of the results I'm getting are null. I'm
I am querying database from my EJB Bean, which is DAO, my query look's

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.