Newbie: Problem with Geolocater |
[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'); And the following in the view: Code: <?php echo $geo;?> 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.
[eluser]GSV Sleeper Service[/eluser]
try Code: print_r($geo); [edit] just looked at the wiki, $geo is an array containing 'country' and 'city' keys. you need to put Code: echo $geo['country'];
[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"
[eluser]GSV Sleeper Service[/eluser]
my mistake, it returns an object, not an array. try this Code: echo $geo->country;
[eluser]Private Dancer[/eluser]
Wont work. Results in: Code: Trying to get property of non-object
[eluser]Pascal Kriete[/eluser]
The object is the first key of the array, so this should work: Code: echo $geo[0]->country;
[eluser]Private Dancer[/eluser]
Ok, this works and i think i get the point now. Thank you guys. |
Welcome Guest, Not a member yet? Register Sign In |