Welcome Guest, Not a member yet? Register   Sign In
Newbie: Problem with Geolocater
#1

[eluser]Private Dancer[/eluser]
Hi forums.

I'm very new with CI and i get a problem. I try to use the Geolocater like described here => http://codeigniter.com/wiki/Geo_Locater/

I set up the DB and also the library like the wiki. I then added the following code to my controller:
Code:
$this->load->library('geolocater');
        $data['geo'] = $this->geolocater->getlocation('<myip>', TRUE);
        
        $this->load->view('start_view', $data);

And the following in the view:
Code:
&lt;?php echo $geo;?&gt;

The only output i then have is "Array" with some whitespace. I think i do a mistake in the controller. I probed a lot. But nothing works. Hope you can help. Smile
#2

[eluser]GSV Sleeper Service[/eluser]
try
Code:
print_r($geo);
in your view, what does that tell you?

[edit] just looked at the wiki, $geo is an array containing 'country' and 'city' keys. you need to put
Code:
echo $geo['country'];
in your view
#3

[eluser]Private Dancer[/eluser]
Ok, the first problem was that the script cant gather any results with my ip. I tried with Googles:

Code:
print_r($geo);

Code:
Array ( [0] => stdClass Object ( [country] => UNITED STATES [city] => PARIS, IL ) )

But when i try now with:
Code:
echo $geo['country'];

It means "Undefined Index"
#4

[eluser]GSV Sleeper Service[/eluser]
my mistake, it returns an object, not an array. try this
Code:
echo $geo->country;
#5

[eluser]Private Dancer[/eluser]
Wont work. Results in:
Code:
Trying to get property of non-object
#6

[eluser]Pascal Kriete[/eluser]
The object is the first key of the array, so this should work:
Code:
echo $geo[0]->country;
#7

[eluser]Private Dancer[/eluser]
Ok, this works and i think i get the point now. Smile

Thank you guys.




Theme © iAndrew 2016 - Forum software by © MyBB