iMedia Ventures

Websites and Mobile Apps

Check if current geolocation is inside polygon

| 0 comments

Share

I had an idea recently after going to the T4G open data hackathon in Fredericton, New Brunswick. To aid in New Brunswick tourism when someon visits the area you could determine which municipality they are in and present them with some ideas for places to visit and things to do. I found a Google Fusion table that has the Nhttp://www.google.com/fusiontables/DataSource?dsrcid=843427#mce_temp_url# which uses polygons. And knowing the location of the person via their mobile device we could determine which boundary they are within.

I haven’t tried modifying this code to work with the boundaries above, but I found this code on the Google Fusion Tables API group.

// check if point is in URL 
var latLng = results[0].geometry.location.toString() 
var SQL=”SELECT URL_VRL_Name FROM 1271853 WHERE 
ST_INTERSECTS(geometry,CIRCLE(LATLNG” + latLng + “,1))”; 
var queryText = encodeURIComponent(SQL); 
var query = new 
google.visualization.Query(‘http://www.google.com/fusiontables/gvizdata?tq=’ 
 + queryText);   
query.send(getURLLookup); 

 

function getURLLookup(response) { 
    numRows = response.getDataTable().getNumberOfRows(); 
      numCols = response.getDataTable().getNumberOfColumns(); 
    if (numRows == 0) { // point not in URL polygon 
        document.getElementById(‘geoMessage’).innerHTML = “** ** OK – 
Address not within a URL/VRL”; 
    } else { 
       document.getElementById(‘geoMessage’).innerHTML = “** ** Address is 
within the: ” + response.getDataTable().getValue(0, 0) + “.”; 
    } 

 

Share

Leave a Reply