Find location with script? How to?

Started by NikolaSN, February 23, 2012, 12:43:58 PM

Previous topic - Next topic

NikolaSN

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

kat

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?

NikolaSN

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

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.

kat

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.

NikolaSN

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...  :-\

geek_andy

Note: I'm not great with php..

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


Seemed to work for me.

NikolaSN

Quote from: geek_andy on February 23, 2012, 05:37:03 PM
Note: I'm not great with php..

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


Seemed to work for me.

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

Advertisement: