Codeigniter Google Maps API V3 Geocoding not working

痞子三分冷 提交于 2019-12-23 06:01:45

问题


I'm trying to use Biostall's Google Maps v3 API to map out a series of addresses, but when I try to type in an address, the Lon Lat produced is 0, 0 every time. It only works if I specifically put in the longitude and latitude of each address. Even the entries which Biostall used on his example video and documentation don't work. I'm trying to also use the geocodeCaching feature, please help.

$this->load->library('googlemaps');

$config = array();
$config['zoom'] = 'auto';
$config['geocodeCaching'] = TRUE;
$config['region'] = 'US';
$config['sensor'] = FALSE;
$this->googlemaps->initialize($config);

$marker = array();
$marker['position'] = '37.429, -122.1519';
$marker['animation'] = 'DROP';
$this->googlemaps->add_marker($marker);

$marker = array();
$marker['position'] = '1600 Amphitheatre Parkway in Mountain View, Santa Clara County, California United States';
$marker['animation'] = 'DROP';
$this->googlemaps->add_marker($marker);

$data['map'] = $this->googlemaps->create_map();

echo print_r($data['map']['markers']);

The marker output:

Array ( [marker_0] => Array ( [latitude] => 37.429 [longitude] => -122.1519 ) [marker_1] => Array ( [latitude] => 0 [longitude] => 0 ) ) 1

This is the map produced:

BIOSTALL's suggestion outputted this: Lat: 0 Lng: 0 Err: OVER_QUERY_LIMIT data_location: http://maps.google.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway+in+Mountain+View%2C+Santa+Clara+County%2C+California+United+States&sensor=false&region=US


回答1:


Thanks for using my library. I have a couple of suggestions:

1) try adding ', United States' to the end of the marker position.

2) I believe there is a 'region' parameter you can set on the map. Try setting this to 'US'.

3) if it's still not working, try going into the library and find the get_lat_lon_from_address() function, then output the result of the URL request.

I hope that helps. I'm going to look at adding a debug mode soon which should help with issues like this. Let me know if any other questions though :)

Steve




回答2:


When it give OVER_QUERY_LIMIT with PHP it can mean that your IP is blocked. Especially when you try too many addresses and also when you don't wait enough between each request. Try to add a pause between each request but most likely you can only wait until the IP is free again (very annoying) or you can try a client side JavaScript. I don't know the exact reason but the reverse geocode works better client side and with JavaScript. You can also get the paid service from Google or use OpenStreetMap.



来源:https://stackoverflow.com/questions/19061445/codeigniter-google-maps-api-v3-geocoding-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!