Advertisement:

Author Topic: Find location with script? How to?  (Read 1671 times)

Offline NikolaSN

  • Semi-Newbie
  • *
  • Posts: 34
Find location with script? How to?
« on: February 23, 2012, 12:43:58 PM »
Hello,

we have forum about RC flying and want to put some weather banner on it. We have code for various cities. So we want to show that banner in one of area defined by Ad management mod.

My question is how I can find location (if entered) of logged user with script/php? Based on that location, correct weather banner will be inserted.

I tried something like:
$message['member']['location']
but that is something working only in Display.template.php.

I want, if it possible, some code which can be entered in Ad Managemend mod.
I successfully entered code for rotating all banners, but that is waste of bandwidth. So is it possible to detect user location with php/javascript code? Some hints needed!

Thanks

Offline K@

  • Lead Support Specialist
  • SMF Master
  • *
  • Posts: 46,315
  • Gender: Male
  • Yum!
Re: Find location with script? How to?
« Reply #1 on: February 23, 2012, 03:56:59 PM »
As this is about a coding matter, I've been utterly rebellious and moved it to the coding board.

I had a search and found this:

http://briancray.com/2009/05/29/find-web-visitors-location-javascript-google-api/

Does that give you any ideas?

Offline NikolaSN

  • Semi-Newbie
  • *
  • Posts: 34
Re: Find location with script? How to?
« Reply #2 on: February 23, 2012, 04:08:46 PM »
Thanks for moving to appropriate place...

Well, this is one of possible solution, but what I think and seek for, is to read variable from SMF which all users are able to set in their profile settings.

That could be done also by reading from DB, but I am sure that there is easier solution with some global variables or similar.

Thanks

MrPhil

  • Guest
Re: Find location with script? How to?
« Reply #3 on: February 23, 2012, 04:12:39 PM »
Mapping IP addresses to location rarely works well. The IP address associated with a given visitor can be (but not always) far, far away from their physical location, especially if their ISP is a large outfit with many IP's in their pool. I've noticed that ads targeted to me can be for a location a hundred or more miles away. I'm sure that advertisers pay big money to get an accurate location for a visitor.

You may want to use that mapping as a default for guests (not signed in), but switch to a member-given location (such as by ZIP/Postal code). Also allow a guest to input a better match for their location.

Offline K@

  • Lead Support Specialist
  • SMF Master
  • *
  • Posts: 46,315
  • Gender: Male
  • Yum!
Re: Find location with script? How to?
« Reply #4 on: February 23, 2012, 04:15:43 PM »
What about......

Let's get this straight, right up-front, OK?

I'm no coder. FAR from it. (Mr. P knows FAR more than I do.) :)

But, I use this http://www.javascriptkit.com/script/script2/dropworldclock.shtml and it works like a charm!

I wonder if the code, for that, could be modified, to do what you want.

Come to that, have a look around that site, coz it has some pretty good stuff on that may help you, with this.

Offline NikolaSN

  • Semi-Newbie
  • *
  • Posts: 34
Re: Find location with script? How to?
« Reply #5 on: February 23, 2012, 04:25:25 PM »
MrPhil,

Thanks, that's my thinking also, and that is reason why I want to read field already populated in user profile.

I found this mode,
http://custom.simplemachines.org/mods/index.php?mod=2496
and that gives me some ideas about how can do it, but this is only for profile view, and I want it somewhere in main header or similar.

I tried to get it with
$context['user'], but it's not stored there...  :-\

Offline geek_andy

  • Semi-Newbie
  • *
  • Posts: 23
  • Gender: Male
    • @geek_andy on Twitter
Re: Find location with script? How to?
« Reply #6 on: February 23, 2012, 05:37:03 PM »
Note: I'm not great with php..

You could try:
Code: [Select]
global $user_settings;
echo $user_settings['location'];

Seemed to work for me.

Offline NikolaSN

  • Semi-Newbie
  • *
  • Posts: 34
Re: Find location with script? How to?
« Reply #7 on: February 23, 2012, 05:45:04 PM »
Note: I'm not great with php..

You could try:
Code: [Select]
global $user_settings;
echo $user_settings['location'];

Seemed to work for me.

Thank you a lot man, this is what i searched for.  ;)