Thread: Geolocation?

    #1
  1. No Profile Picture
    Contributing User
    ASP Explorer (0 - 99 posts)

    Join Date
    Jan 2014
    Posts
    65
    Rep Power
    4

    Geolocation?


    Hi guys

    I am looking to build a page (asp) which when loaded by my users will display their location. So, it would simply show their town/city and county (UK).

    I've read that this is possible by using the user's browser (or IP) to determine their rough location. I have looked at a multitude of articles but they are extremely complex to someone at my level. All I want to do is simply display the user's location on my page (ie <%=town%>, <%=county%>).

    Is there an easy way to do this via asp?

    Any help would be fully appreciated

    Best regards

    Rod from the UK
  2. #2
  3. Guru
    ASP Adventurer (500 - 999 posts)

    Join Date
    May 2003
    Location
    USA
    Posts
    923
    Rep Power
    79
    Well I guess for privacy reasons browsers don't report that information about the users. And of course someone using a proxy could even fool that if it did.

    Seems like the usual method is to get that info from the users when they register or update their profile and then of course it's easy to pull out the info about the users from the database.
    J. Paul Schmidt
    www.Bullschmidt.com - Freelance Web and Database Developer
    www.Bullschmidt.com/DevTip.asp - Classic ASP Design Tips
  4. #3
  5. No Profile Picture
    Contributing User
    ASP Explorer (0 - 99 posts)

    Join Date
    Jan 2014
    Posts
    65
    Rep Power
    4
    Thanks Paul

    Best regards

    Rod from the UK
  6. #4
  7. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Apr 2017
    Posts
    5
    Rep Power
    0
    If user users browser with HTML5 and he ALLOW this information, you can get it:

    Code:
    <script language="Javascript">
    
    function getLocation() {
        if (navigator.geolocation) {
            navigator.geolocation.getCurrentPosition(showPosition);
        }
    }
    
    function showPosition(position) {
       var lat = position.coords.latitude;
       var lon = position.coords.longitude;
    
       var xmlhttp;
       if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
          xmlhttp = new XMLHttpRequest();
       } else { // code for IE6, IE5
          xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
       }
       xmlhttp.open("GET", "geocode.asp?lat=" + position.coords.latitude + "&lon=" + position.coords.longitude, false);  // send the position to other ASP, so you can save. You can make a page to show on google maps
       xmlhttp.setRequestHeader("Content-Type", "text/html; charset=iso-8859-1");
       xmlhttp.onreadystatechange = function () {
    	 if (xmlhttp.status == 404 || xmlhttp.status == 500) {
    		xmlhttp.abort();
    		return false;
    	 }
       }
       xmlhttp.send(null);
    }
    </script>
    Last edited by Will-O-The-Wisp; April 18th, 2017 at 04:04 PM.
  8. #5
  9. No Profile Picture
    Contributing User
    ASP Explorer (0 - 99 posts)

    Join Date
    Jan 2014
    Posts
    65
    Rep Power
    4
    Hi lwen

    Thank you so much for your reply, it's very much appreciated

    Using your script, how would I display the user's location on my page (ie <%=town%>, <%=county%>)?

    Any further help would be fully appreciated

    Best regards

    Rod from the UK

Similar Threads

  1. Replies: 0
    Last Post: April 7th, 2011, 05:00 PM
  2. Replies: 0
    Last Post: December 24th, 2010, 11:00 PM
  3. Disney Makes a Big Bet on Geolocation with Gowalla (Mashable)
    By RSS_News_User in forum Technology News
    Replies: 0
    Last Post: November 18th, 2010, 08:00 AM
  4. Replies: 0
    Last Post: March 30th, 2010, 12:00 AM
  5. Replies: 0
    Last Post: October 8th, 2008, 04:04 PM

IMN logo majestic logo threadwatch logo seochat tools logo