Advertisement:

Author Topic: Location based on IP  (Read 4012 times)

epicrevolt

  • Newbie
  • *
  • Posts: 2
Location based on IP
« on: September 23, 2011, 08:56:16 am »
I thought it would have actually been a core feature of OSClass. I mean how cool would it be if it could detect your location based on your IP address. of course the user would have the option to change that location, but it would be a great improvement if the location could automatically be filled in, or not allow the user to choose a location at all.
Such as a site I am developing. It would improve workflow if the user didn't have to type in a location everytime. I don't want the users to be able to choose, I want the IP to find their location.
It's a relatively simple idea, but you get the point.
UPDATE:
Doing some research I found IP Info DB http://www.ipinfodb.com/ip_location_api.php
I am integrating it into my website, but I don't know how I would make a plugin version of it, currently it is only in the theme, auto-filling in the boxes. It would be cool if someone could do some javascript/jquery magic on this.
« Last Edit: September 23, 2011, 09:12:12 am by epicrevolt »

_CONEJO

  • Administrator
  • Hero Member
  • *****
  • Posts: 4689
Re: Location based on IP
« Reply #1 on: September 23, 2011, 10:18:54 am »
Hi epicrevolt,

It's a great idea, will take a look at it. If you already develop something, we could help you finish it.

Thanks

epicrevolt

  • Newbie
  • *
  • Posts: 2
Re: Location based on IP
« Reply #2 on: September 25, 2011, 09:00:46 am »
It seems that since mine automatically fills in the data because I edited the item-post.php, A user can not re-select a location.
I suck at Javascript, so I am just doing what I can.

gr8555

  • Newbie
  • *
  • Posts: 10
Re: Location based on IP
« Reply #3 on: September 01, 2012, 01:12:23 am »
Does anyone have a working mod for this? i am very much interested! :)

web2graphics

  • Jr. Member
  • **
  • Posts: 74
Re: Location based on IP
« Reply #4 on: September 01, 2012, 07:36:04 am »

me too

Legion

  • Hero Member
  • *****
  • Posts: 622
Re: Location based on IP
« Reply #5 on: October 07, 2012, 01:32:05 pm »
it would be great if develope can convert it to plugin

lucky_strike

  • Guest
Re: Location based on IP
« Reply #6 on: November 16, 2012, 03:03:05 am »
wrong data they provide
 Your IP address information

    IP address : 87.217.161.168
    Country : SPAIN
    State/Province : MADRID
    City : MADRID...
im in  gran canaria.
 :)

you should change to google  api.. having 2500 free calls to api its enough...
 ive started a subject here...maybe you could help :)
http://forums.osclass.org/plugins/beginners-guide-how-to-make-a-plugin-plugins-google_ad_locator-search_by_zip/

krishields3

  • Newbie
  • *
  • Posts: 37
Re: Location based on IP
« Reply #7 on: November 20, 2012, 08:57:48 am »
Yea... that is a problem with using only the IP. Take myself for example, my actual location is Ridgeway, IA, but my ISP assigns me a public IP from Winona, MN. What you would do if you wanted to go this route is to reverse geocode through google maps the coordinates snagged from the users IP using some source like: www.ipinfodb.com

I am currently working on a script which uses the IP to get a guest user coordinates so that I may serve them the most appropriate ads. I require the city and geocode that when a user registers so I have a more accurate representation of where they are located which allows for more accurate ads.   

Basically, all we need to do is something like this:
Code: [Select]
$IP = $_SERVER['REMOTE_ADDR'];
$QU = file_get_contents('http://api.ipinfodb.com/v3/ip-city/?key=YOURKEY&ip=' . $IP);
$Curr_User_Location = GetUserIPLocation($QU);
Code: [Select]
function GetUserIPLocation($QU) {
    $CurrString = "";
    $Counter = 0;
    $LAT = "";
    $LON = "";
    $REG = "";

    for ($c = 0; $c<strlen($QU); $c++) {
        if ($QU[$c] != ";") {
            $CurrString = $CurrString.$QU[$c];
        }
        else {
            if ($Counter == 5) {
                $REG = $CurrString;
            }
            else if ($Counter == 8) {
                $LAT = $CurrString;
            }
            else if ($Counter == 9) {
                $LON = $CurrString;
            }
            $Counter++;
            $CurrString = "";
        }
    }

    $Curr_User = array('d_coord_lat'  => $LAT,
                       'd_coord_long' => $LON,
                       's_region'     => $REG);
   
    return $Curr_User;
}