Posts Tagged ‘geo’

Get Location Information based on an address, city or country name

Posted in Snippets Ideas on January 10th, 2010 by admin – Be the first to comment

In our last post we explained how to use GeoIP easily in CodeIgniter. Now we are interested in getting location information from a particular address using a Geocoder tool. For that reason, we’d recommend to take a look over How to use Google Maps API with PHP from Zimuel’s blog.

Zimuel exposes the following scenario:

Scenario: you have to check the validity of the geo data of a list of customers stored into a database. Using the Google Maps API you can easly compare the data stored into your database with the google data and fix the errors.

Moreover, his solution using Google Maps API proposes the following solution.

A PHP class that uses the Google Maps API to provide geographic information from a generic address (city, country, street+city, country. etc.).

read more »

Related searches:

  • $gmap->getinfolocation
  • gmaps place search db
  • google map api with street city country and zipcode provided
  • google maps is empty ie
  • how gmap takes location latitude and longitude
  • how to fetch data by country code in codeigniter
  • how to fetch gmap using zip code
  • php gmap 3 class
  • php gmaps
  • php gmaps search address

Using GeoIP in CodeIgniter application

Posted in Snippets Ideas on January 9th, 2010 by admin – 3 Comments

The company called Maxmind published free resources to use Geo localized IP services in your web applications. I remember this service is there from long time ago.

Now, we are interested in getting geo information from users in a website, so it could be a good idea to integrate GeoIP services as a CodeIgniter plugin.

@Burak posted a short but nice article at phpandstuff.com explaining how to integrate GeoIP in a PHP script.

So, based on that article, I’d integrate the GeoIP as a plugin, by following these steps:

1. Create a new plugin file under application/plugins/geo_ip.php and I put there the content that is inside geoip.inc

2. We’d need to copy the GeoIP.dat file to any location inside our application. I used resources/geo/GeoIP.dat as location.

3. Then we’d need to load the plugin file, we can do that on any particular controller file (on demand) or we can add it as autoloaded plugin in application/config/autoload.php

4. I went to the controller class where I want to use GeoIP to grab the user’s country name and code, and put this snippet:


        $gi = geoip_open('resources/geo/GeoIP.dat',GEOIP_STANDARD);
        $country_code = geoip_country_code_by_addr($gi, $_SERVER['REMOTE_ADDR']);
        $this->data['country_code'] = $country_code;
        $country_name = geoip_country_name_by_addr($gi, $_SERVER['REMOTE_ADDR']);
        $this->data['country_name'] = $country_name;
        // close the database
        geoip_close($gi);

Update 2010-04-09: The code below was updated accordingly to Kubilay comment, thanks. Row 5 was switched with row 4.

That’s all, assuming that finally you will have the Country Code and Country Name under $this->data variable. You can see more info about why I use this way to pass information to view, under Using a Super Controller Class in CodeIgniter.

Related searches:

  • codeigniter geoip
  • integrate geo-ip for codeigniter
  • Maxmind codeigniter
  • geoip codeigniter
  • codeigniter maxmind
  • codeigniter ip country
  • geoip in codeigniter
  • codeigniter ip to country
  • geoip with codeigniter
  • geoip integration in codeigniter