For a while now , i have been pondering how this could be done and if the results would be any use. What i am talking about is getting the users Latitude / Longitute & IP address that is running the survey. Now the first thing to mention is that it would not realy be their IP address, but the IP address or location of the machine that is used to connect to the internet. Anyway this is the code i came up with and i am sure it will be of use.
Another thing to mention is that if you are trying to run this on an intranet then it would not give you the results you wanted. It should be possible to design something similar and we may leave that for another article.
ok , so how are we going to do this. Well in this exmple we are going to use the website IPLOCATOR to get the information for us. The infomation that this site profides us with based on the IP address is.
WebServiceInfo "WebServiceInfo" text [0..2024]; GeneralHelp "Here is some general information : Provided by http://www.geobytes.com/IpLocator.htm CountryId this field is an internal key used to relate a specific row in this table to related rows in the Regions, Cities, and Dmas tables. This is the primary key and is unique. The number “113” for example is the key for India. Country this field is a string representation of the country name, for example, “India”, “Singapore” or “Canada”. FIPS104 FIPS104 or more precisely FIPS 10-4 is a publication by the Federal Information Processing Standards body that identifies geopolitical entities around the world with a code. For example, “AS07” is the state of Victoria in Australia. This field represents logical groupings of these four letter codes, so in this example the letters “AS” would be stored in the “FIPS104” field. More information about this publication can be found at the National Imagery and Mapping Agency at http://www.nima.mil and http://www.nima.mil/gns/html/index.html. ISO2 this field represents the “A 2” column in the ISO 3166 document which lists each country with associated alpha and numeric codes. More information on ISO 3166 standard can be found at the International Organization for Standardization web-site at http://www.iso.org/iso/en/prods-services/iso3166ma/02iso-3166-code-lists/list-en1.html. An example is “US” which represents the United States of America. ISO3 this field represents the “A 3” column in the ISO 3166 document which lists each country with associated alpha and numeric codes. More information on ISO 3166 standard can be found at the International Organization for Standardization web-site at http://www.iso.org/iso/en/prods-services/iso3166ma/02iso-3166-code-lists/list-en1.html. An example is “GTM” which represents Guatemala. ISON this field represents the “Number” column in the ISO 3166 document which lists each country with associated alpha and numeric codes. More information on the ISO 3166 standard can be found at the International Organization for Standardization web-site at http://www.iso.org/iso/en/prods-services/iso3166ma/02iso-3166-code-lists/list-en1.html. An example is “036” which represents Australia. Internet this field represents the “ccTLD” code designated by IANA (Internet Assigned Numbers Authority) which is employed in the DNS to identify hosts in various countries around the world. For example, the code “uk” is assigned to the United Kingdom. The “ccTLD” codes are based on the “A 2” column of the ISO 3166 standard document. More information on the Internet Assigned Numbers Authority can be found at http://www.iana.org, more information on the International Organization for Standardization can be found at http://www.iso.org. Capital this field is a string representation of a given countries capital city, for example, the capital of United States is “Washington, DC”. This information was referenced from the CIA web-site and can be found at http://www.cia.gov/cia/publications/factbook/. MapReference this field is a string representation of a given countries, major reference point in the world, for example, the map reference for Canada is “North America”. This information was referenced from the CIA web-site and can be found at http://www.cia.gov/cia/publications/factbook/. NationalitySingular this field is a string representation, referring to a singular expression of a given countries nationality. For example, the singular expression of a person from the United States would be “American”. This information was referenced from the CIA web-site and can be found at http://www.cia.gov/cia/publications/factbook/. NationalityPlural this field is a string representation, referring to a plural expression of a given countries nationality. For example, the plural expression of people from the United States would be “Americans”. This information was referenced from the CIA web-site and can be found at http://www.cia.gov/cia/publications/factbook/. Currency this field is a string representation of a given countries currency, for example, the currency of United States would be “US Dollar”. This information was referenced from the CIA web-site and can be found at http://www.cia.gov/cia/publications/factbook/. CurrencyCode this field is a 3 character string representation of a given countries currency code. The codes are based on the ISO 4217 where the first 2 characters are made up of the countries Internet code and the last is a currency designator. For example the currency code “USD” is the code for the US Dollar. More information on the ISO standardization can be found at http://www.iso.org. Population this field represents a given countries population, based on an estimate as of July 2001, and is referenced from the CIA web-site. More information can be found at the CIA web-site at http://www.cia.gov/cia/publications/factbook/. CountryTitle this field is a string representation of a given country's title as it would appear in a sentence. For example:- The “title” for United States is “The United States”. " info; known "known" style( Columns = 40, Rows = 1) text; countryid "countryid" style( Columns = 40, Rows = 1) text; country "country" style( Columns = 40, Rows = 1) text; fips104 "fips104" style( Columns = 40, Rows = 1) text; iso2 "iso2" style( Columns = 40, Rows = 1) text; iso3 "iso3" style( Columns = 40, Rows = 1) text; ison "ison" style( Columns = 40, Rows = 1) text; internet "internet" style( Columns = 40, Rows = 1) text; capital "capital" style( Columns = 40, Rows = 1) text; mapreference "mapreference" style( Columns = 40, Rows = 1) text; nationalitysingular "nationalitysingular" style( Columns = 40, Rows = 1) text; nationalityplural "nationalityplural" style( Columns = 40, Rows = 1) text; currency "currency" style( Columns = 40, Rows = 1) text; currencycode "currencycode" style( Columns = 40, Rows = 1) text; population "population" style( Columns = 40, Rows = 1) text; countrytitle "countrytitle" style( Columns = 40, Rows = 1) text; regionid "regionid" style( Columns = 40, Rows = 1) text; region "region" style( Columns = 40, Rows = 1) text; regioncode "regioncode" style( Columns = 40, Rows = 1) text; adm1code "adm1code" style( Columns = 40, Rows = 1) text; cityid "cityid" style( Columns = 40, Rows = 1) text; city "city" style( Columns = 40, Rows = 1) text; latitude "latitude" style( Columns = 40, Rows = 1) text; longitude "longitude" style( Columns = 40, Rows = 1) text; timezone "timezone" style( Columns = 40, Rows = 1) text; locationcode "locationcode" style( Columns = 40, Rows = 1) text; dma "dma" style( Columns = 40, Rows = 1) text; certainty "certainty" style( Columns = 40, Rows = 1) text; isproxynetwork "isproxynetwork" style( Columns = 40, Rows = 1) text; mapbytesremaining "mapbytesremaining" style( Columns = 40, Rows = 1) text; Page1 "Location Iformation" page( GeneralHelp, countryid, country, fips104, iso2, iso3, ison, internet, capital, mapreference, nationalitysingular, nationalityplural, currency, currencycode, population, countrytitle, regionid, region, regioncode, adm1code, cityid, city, latitude, longitude, timezone, locationcode, dma, certainty, isproxynetwork, mapbytesremaining );
and then we need some routing
Routing(Web) Dim sValue, oArray, oItem,oValues,sName,sAnswer WebServiceInfo.LayoutTemplate = "WebServiceInfo.htm" WebServiceInfo.ask() sValue = WebServiceInfo.response.Value sValue = replace(sValue,mr.Lf,"") sValue = Replace(sValue,"title>PHPALL Template","") sValue = Replace(sValue," "" Then oValues = split(oItem,""" content=""") sName = Replace(Replace(oValues[0],"meta name=",""),"""","") sAnswer = oValues[1] IOM.Questions[sName].Response.value = replace(sAnswer,"""","") End If Next Page1.LayoutTemplate = "Location.htm" Page1.ask() End Routing
The way this works is simple. The first page stores the information sent back from the webservice in a text question , the results of this are then split out into the other questions in the survey and then presented on the screen.
The first question uses the following template.
Location mrBannerText test
Previous Next GoTo
you will see that on this page is a hyperlink that requires you to click it. This of course could be changed so that it just runs , but for the purpose of this testing we have left it as a link.
The web URL that is run is the following ,
http://www.geobytes.com/IpLocator.htm?GetLocation&template=phpAll.txt
when the link is clicked you will get a blank page, but just do a view source of the page and you will see all the info you need. There are several other urls that could be used and you can see them herehttp://forums.geobytes.com/viewtopic.php?t=593 ( you will just have to change the way Data collection splits out the data. )
Once this link is clicked the webservice gets the relevant information, pastes it into the Data Collection question and then clicks the next button. The base Javascript that does this was found on “www.dynamicdrive.com” and has had a few changes.
/*********************************************** * Dynamic Ajax Content- © Dynamic Drive DHTML code library (www.dynamicdrive.com) * This notice MUST stay intact for legal use * Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code ***********************************************/ var bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no) var loadedobjects="" var rootdomain="http://"+window.location.hostname var bustcacheparameter="" function ajaxpage(url, containerid){ var page_request = false if (window.XMLHttpRequest) // if Mozilla, Safari etc page_request = new XMLHttpRequest() else if (window.ActiveXObject){ // if IE try { page_request = new ActiveXObject("Msxml2.XMLHTTP") } catch (e){ try{ page_request = new ActiveXObject("Microsoft.XMLHTTP") } catch (e){} } } else return false page_request.onreadystatechange=function(){ loadpage(page_request, containerid) } if (bustcachevar) //if bust caching of external page bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime() page_request.open('GET', url+bustcacheparameter, true) page_request.send(null) } function loadpage(page_request, containerid){ if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)) { document.getElementById(containerid).value=page_request.responseText var oBut = document.getElementById("_NNext"); oBut.click(); } }
The last template is just a normal template to display all the answers on the page. When you run this survey you will see that it gets the lots of information about your location , but not the IP address. Hunting arround the net i did not find anything sutable for my needs so what i did was to make a very small php file with the following code in it ,
and then placed the file on a test website
http://test.smarterdimensions.com/getip.php
If you run this url it will just return the IP address
So adding it to the mdd was simple , i just created a new IPAddress question.
IPAddress "IPAddress" text;
and then in the metadata i added
IPAddress.LayoutTemplate = "IPAddress.htm" IPAddress.Ask() IPAddress.Show()
The IPAddress.htm template is exactly the same as the “WebServiceInfo.htm” but with the url to get changed from
http://www.geobytes.com/IpLocator.htm?GetLocation&template=phpAll.txt
to
http://test.smarterdimensions.com/getip.php
And there you have it , a survey that gets IP and Lat and Lng information. As always if you have some comments on this or any other posts , add a comment and i will get back to you as soon as i can.
( if you want the files for this click here )
I really liked your article 🙂
I know Its too much to ask but is there any posibility to show us a tutorial exactly how use it? I’m not really good in web programming