Welcome Guest, Not a member yet? Register   Sign In
BIOSTALL googlempas API
#1

[eluser]stingray9[/eluser]
Hey,

i've used it before and had never problems with it, in contrary, it's a great library.
Though, i'm facing a problem now.

In the past I've always set a lat and lng for my $marker['position'], but now i want to do it with an adress string from my database.

This is in my controller:

Code:
$this->load->library('googlemaps');
         $this->googlemaps->initialize();
         $config['zoom'] = '18';
         $query = $this->db->query("SELECT * FROM location")->result();
        foreach ($query as $row)
        {    
        $marker = array();
        $marker['position'] = $row->address;
        $this->googlemaps->add_marker($marker);
        }
        
        $data['map'] = $this->googlemaps->create_map();

But it always gives me a marker at 0,0
And in my database is one record with a string in it. If i put that string in the information box of that marker, it shows it, but still, it's not shown off on the right place. So the value is pulled out of my database, but the position isn't well defined.

Can anyone please help me out on this matter?
#2

[eluser]stingray9[/eluser]
No one has experience with it, or knows a solution?
#3

[eluser]BIOSTALL[/eluser]
Hi stringray9,

The reason a marker would be placed at '0, 0' is if the address wasn't recognised or wasn't exact enough. Two things I would recommend:

1) Make the address more exact. Possibly add the country to the end.
2) Pass a 2 letter 'region' parameter when first initializing the map.

Cheers,

Steve
#4

[eluser]skunkbad[/eluser]
Can't you just use the geocoder API to get the GPS coordinates?

Code:
$url = 'http://maps.googleapis.com/maps/api/geocode/json?address='
                    . $address
                    . '&sensor=false';

if( $response = @file_get_contents( $url ) )
{
        $arr = json_decode($response);

        $lat = $arr->results[0]->geometry->location->lat;

        $lng = $arr->results[0]->geometry->location->lng;
}
#5

[eluser]BIOSTALL[/eluser]
Hi skunkbad. The library already does exactly that. The problem arises when an address is not recognised though. In which case no lat long are returned.
#6

[eluser]skunkbad[/eluser]
In my experience, the address had to be formatted correctly to work. You mentioned "making the address more exact", and I have a feeling this is the problem, as I never had a problem with an address after I figured out how to give Google what it wants.




Theme © iAndrew 2016 - Forum software by © MyBB