HTML Logo by World Wide Web Consortium (www.w3.org). Click to learn more about our commitment to accessibility and standards.

Record users lat/long when they join

Login / Search

 [ Join | More ]
 Add topic 
Posted
Rating:
#71384
Avatar

Community saint

I think Chris needs to look at it too since the Geo-Lookup function in "Investigate user, by IP" hasn't worked for me at all. (See View topic: Geo-lookup error - ocPortal).

I suspect Maxmind made some changes to their offerings which are not reflected in ocPortal.

Bob
Back to the top
 
Posted
Rating:
#71385
Avatar

Community saint

"Investigate user" is a separate issue. Looks like the API has changed from:

Code

http://www.maxmind.com/app/locate_ip?ips=11.22.33.44
to:

Code

http://www.maxmind.com/app/locate_demo_ip?ips=11.22.33.44

And you can fix that yourself in the meantime by updating LOOKUP_SCREEN.tpl.

The geolocate_ip() function is country level only, so it is working as expected.

The timezone problem is a known issue that should be fix in v7.1.1.

Do you have a Samsung Galaxy S / Galaxy S II ? If so, why not check out my ScreenFree FM Radio .
Back to the top
 
Posted
Rating:
#71388
Avatar

Community saint

Made the change in LOOKUP_SCREEN.tpl and that seems to have fixed things.

Hopefully, we can take advantage of GeoLite City which is also free. The US (and Canada and Australia and on and on) are mighty big countries and it would be good to see what part of the country people are from.

Thanks, as always, for your help.

Bob


Last edit: by BobS
Back to the top
 
Posted
Rating:
#71390
Avatar

Community saint

temp-

Just noticed that the changed URL delivers city and metro code - everything except postal code which is understandable without a street address.

Maybe your code can be modified to emulate the Geo_lookup code if the GeoLite City code is not workable.

Bob
Back to the top
 
Posted
Rating:
#71391
Avatar

Community saint

"Geo_lookup" and "GeoLite City" are essentially the same thing. The two main differences are that Geo_lookup is an online demo (max 25 lookups per day per user) that returns slightly higher quality information because it uses their commercial data, whereas GeoLite City is their downloadable version that you install on your own server.

Free Version:

Over 99.5% on a country level and 79% on a city level for the US within a 25 mile radius.
Commercial Version:

Over 99.8% on a country level and 83% on a city level for the US within a 25 mile radius.

It shouldn't be a problem getting GeoLite City to work. It looks straight forward.

Do you have a Samsung Galaxy S / Galaxy S II ? If so, why not check out my ScreenFree FM Radio .
Back to the top
 
Posted
Rating:
#71413
Avatar

Community saint

No doubt straight-forward for you but the rest of us mere mortals will be most interested in your findings.  ;)

Bob
Back to the top
 
Posted
Rating:
#71425
Avatar

Community saint

temp1024 said

"Investigate user" is a separate issue. Looks like the API has changed from:

Code

http://www.maxmind.com/app/locate_ip?ips=11.22.33.44
to:

Code

http://www.maxmind.com/app/locate_demo_ip?ips=11.22.33.44

And you can fix that yourself in the meantime by updating LOOKUP_SCREEN.tpl.

Weird. I decided to go back and make this change using the template editor in ocPortal but then it still is using the old URL. I've cleared cache and verified the contents of /templates/custom/LOOKUP_SCREEN.tpl.

Wonder why it is still using the old URL.

I am really hoping that all this geo-location stuff can be based on GeoLite City which would produce the best results and not have limitations on the number of uses per day.

Bob
Back to the top
 
Posted
Rating:
#71426
Avatar

ocStaff (admin)

Will switch to http://www.infosniper.net/, that seems to work.



Become a fan of ocPortal on Facebook or add me as a friend.

Expand: Was I helpful? Was I helpful?

Expand: Follow me on Twitter Follow me on Twitter







If I answered something that you think should be in the documentation, please take the initiative and add it to the community documentation. We really need people to help out here and build a well-organised large support resource.
Back to the top
 
Posted
Rating:
#71427
Avatar

Community saint

Chris-

Just looked at inforsniper.net and it looks like it provides only country-level information. Any chance for city-level information?

I like the idea of GeoLite City since the data resides locally on your server which should mean faster lookups. People would just need to remember to download the updated binary once a month which could be out in the to-do list.

Bob
Back to the top
 
Posted
Rating:
#71428
Avatar

ocStaff (admin)

It is saying cities when I've just tried a couple of IPs :). We won't be implementing any more sophisticated APIs, just replacing a link given the old service apparently has remained offline. We're still essentially under a feature-freeze, and I'm afraid it will continue to be the case that non-trivial ocProducts-funded work needs a very strong commercial imperative for us to do it for the foreseeable future.



Become a fan of ocPortal on Facebook or add me as a friend.

Expand: Was I helpful? Was I helpful?

Expand: Follow me on Twitter Follow me on Twitter







If I answered something that you think should be in the documentation, please take the initiative and add it to the community documentation. We really need people to help out here and build a well-organised large support resource.
Back to the top
 
Posted
Rating:
#71434
Avatar

ocStaff (admin)

Let me just qualify what I mean there a little…

We continue to invest in ocPortal, heavily, but we have to make pointed strategic decisions where to do it. That is either:
  • reaching parity with competitors where we might be perceived to be weak
  • reaching parity with general rises in the industry (e.g. quality of UI design)
  • leading in innovation
  • solving big problems for large segments of our userbase (which often is innovation, when everything else in the market is insufficient – e.g. the relatively new CSS editor).

Through this, we make ocPortal a better product for large groups of people, and thus gain more users, grow the community, and very indirectly get ourselves more customers, thus justifying the investment.

Other than these things, there are a lot of things that I agree could be improved (most suggestions people make!), but the realistic truth is that they are not improvements that will give us a measurable competitive advantage, and therefore as a business ocProducts can't pay for them. I'm very happy for someone else to put them into ocPortal – people can always ask for subversion-write access for example and become commiters, or simply post patches. I'm also very happy to do them if we get a wealthy donor. But I just can't develop them or authorise my staff to, if I don't see a commercial imperative.

That's particularly the case at the moment, where we're in what could almost be called a global depression, we need to fight to bring in money just like any other business – and unlike many of our competitors, we're not just running off huge venture capital investments.



Become a fan of ocPortal on Facebook or add me as a friend.

Expand: Was I helpful? Was I helpful?

Expand: Follow me on Twitter Follow me on Twitter







If I answered something that you think should be in the documentation, please take the initiative and add it to the community documentation. We really need people to help out here and build a well-organised large support resource.
Back to the top
 
Posted
Rating:
#71439
Avatar

Community saint

Chris-

I fully understand your position and dilemma and you are doing a great job of moving ocPortal forward.

Perhaps temp1024 will consider becoming a committer to the svn - he already has generously shared a number of improvements to ocPortal. It would be nice (and better for all involved) if those changes became part of ocPortal.

Bob
Back to the top
 
Posted
Rating:
#71480
Avatar

Community saint

And perhaps temp1024 will not.

Do you have a Samsung Galaxy S / Galaxy S II ? If so, why not check out my ScreenFree FM Radio .
Back to the top
 
Posted
Rating:
#71482
Avatar

Community saint

temp1024 said

And perhaps temp1024 will not.
Fair enough. Your efforts are already well-represented in the recent releases.

Bob
Back to the top
 
Posted
Rating:
#71512
Avatar

Community saint

Below is the version that uses GeoLiteCity data. If doesn't find it it will revert back to using the old method.

Before you can use it, you will need to create a /data_custom/GeoLiteCity/ directory and copy the following files from maxmind.com into it:

Code

http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
http://geolite.maxmind.com/download/geoip/api/php/geoip.inc
http://geolite.maxmind.com/download/geoip/api/php/geoipcity.inc
http://geolite.maxmind.com/download/geoip/api/php/geoipregionvars.php

then unzip GeoLiteCity.dat.gz .

PHP code


        
/** temp1024
        * Add default latitude/longitude infromation to custom profile fields of new accounts.
        *
        * Use the users IP address to determin the lat/long of the country (or city if possile) they are connecting from.
        */

        // Only proceed if ocUsermap is installed. Thats where lat/long will be saved.
        
if(file_exists(get_file_base().'/sources_custom/blocks/main_google_map_users.php'))
        {
            
// Use maxmind.com's GeoLiteCity data if available.
            
if(file_exists(get_file_base().'/data_custom/GeoLiteCity/GeoLiteCity.dat'))
            {
                require_once(
get_file_base().'/data_custom/GeoLiteCity/geoipcity.inc');
                require_once(
get_file_base().'/data_custom/GeoLiteCity/geoipregionvars.php');
                
$gi geoip_open(get_file_base().'/data_custom/GeoLiteCity/GeoLiteCity.dat',GEOIP_STANDARD);
                
$record geoip_record_by_addr($gi,get_ip_address());
                if(
$record)
                {
                           
$lat $record->latitude;
                           
$lng $record->longitude;
                }
                
geoip_close($gi);
            }

            if(!isset(
$lat))
            {
                
// GeoLiteCity not available of failed to get lat/long. Try with stats module.
                
if(addon_installed('stats'))
                {
                    
$address geolocate_ip();    // Get ISO country code
                    // Use google maps API v3 to convert country code to latitude/longitude
                    
define "MAPS_HOST""maps.google.com" );
                    
$base_url "http://" MAPS_HOST "/maps/api/geocode/xml";
                    
$request_url $base_url "?address=" urlencode($address) ."&sensor=false";
                    if(
$xml simplexml_load_file($request_url))
                    {
                        if (
$xml->status == "OK")
                        {
                            
$lat $xml->result->geometry->location->lat;
                            
$lng $xml->result->geometry->location->lng;
                        }
                    }
                }
            }

            if(isset(
$lat))
            {
                
// We have a lat/long, now adjust it so that no two members default to the exact same location. Members will circle their country/city centre in a series of concentric circles.
                
$radius=((int)($member_id/360))*.0001 +.001;
                
$lat=$lat+$radius*sin($member_id*2*M_PI/360);
                
$lng=$lng+$radius*cos($member_id*2*M_PI/360);

                
$lat_field_name='ocp_latitude';    // Custom profile field name to store latitude in.
                
$lng_field_name='ocp_longitude';   // Custom profile field name to store longitude in.

                
$latitude_cpf_id=$GLOBALS['FORUM_DB']->query_value_null_ok('f_custom_fields f LEFT JOIN '.$GLOBALS['FORUM_DB']->get_table_prefix().'translate t ON f.cf_name=t.id','f.id',array('text_original'=>$lat_field_name));
                
$longitude_cpf_id=$GLOBALS['FORUM_DB']->query_value_null_ok('f_custom_fields f LEFT JOIN '.$GLOBALS['FORUM_DB']->get_table_prefix().'translate t ON f.cf_name=t.id','f.id',array('text_original'=>$lng_field_name));

                
// Save lat/long
                
$GLOBALS['FORUM_DB']->query_update('f_member_custom_fields',array('field_'.$latitude_cpf_id=>$lat,'field_'.$longitude_cpf_id=>$lng ),array('mf_member_id'=>$member_id),'',1);
            }
        }


Note that as /data_custom/GeoLiteCity/ is a new directory is needs a bit of security.

Add an empty index.html to stop people from seeing a directory listing.

Add a .htaccess containing

Code

order deny,allow
deny from all
to prevent people from directly executing any code in that directory.

Do you have a Samsung Galaxy S / Galaxy S II ? If so, why not check out my ScreenFree FM Radio .
Back to the top
 
Posted
Rating:
#71519
Avatar

Community saint

Thanks temp-

I can hardly wait to give this a try. I will work on it this afternoon. Does this just replace your prior code in /pages/modules_custom/join.php?

Bob


Last edit: by BobS
Back to the top
 
Posted
Rating:
#71530
Avatar

Community saint

temp-

Got this installed and I really appreciate your effort. Now, instead of being located outside Wichita, Kansas, I'm located within a few hundred yards of my home. I am quite impressed.

Hopefully, Chris will incorporate this into the standard ocPortal or the ocUsermap add-on.

Thanks again.

Bob



Last edit: by BobS
Back to the top
 
Posted
Rating:
#71536
Avatar

Community saint

BobS said

I'm located within a few hundred yards of my home.
Not bad, mine is within about 16,400 yards (15 km), which is more then accurate enough for a general location.

The best part is that no one will know how accurate unless you tell them.

I'd be very surprised if he included it for several reasons. In any case the most he could include would be my code and not the maxmind code or data due to licensing restrictions.

Do you have a Samsung Galaxy S / Galaxy S II ? If so, why not check out my ScreenFree FM Radio .
Back to the top
 
Posted
Rating:
#71537
Avatar

Community saint

temp-

I just meant the changes in join.php which you said falls back to the existing code gracefully.

Then it's 4 easy downloads and uploads. But even if not included, it's a really easy installation and the results are fantastic.

I just had my sister sign up and she was about a mile and one-half off which surprised me because she is located in the hills some 5 miles from the town where she lives.

Bob

I'd be satisfied with accuracy to within 25 miles in rural areas. Of course, all of that is beyond your control and relies on the data Maxmind provides but you getting this working gets an A+ from me.
Back to the top
 
1 guests and 0 members have just viewed this: None
Control functions:

Quick reply   Contract

Your name:
Your message: