Then go back to basics. Get it working and move forwards. So step 1, make sure your key actually work. In a bash/command prompt do: -
curl "https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&key=MY_KEY_HERE"
And you’ll get a nice big fat JSON
{
"results" : [
{
"address_components" : [
{
"long_name" : "1600",
"short_name" : "1600",
"types" : [ "street_number" ]
},
{
"long_name" : "Amphitheatre Parkway",
"short_name" : "Amphitheatre Pkwy",
"types" : [ "route" ]
},
{
"long_name" : "Mountain View",
"short_name" : "Mountain View",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Santa Clara County",
"short_name" : "Santa Clara County",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "California",
"short_name" : "CA",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
},
{
"long_name" : "94043",
"short_name" : "94043",
"types" : [ "postal_code" ]
}
],
"formatted_address" : "1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA",
"geometry" : {
"location" : {
"lat" : 37.422064,
"lng" : -122.0840915
},
"location_type" : "ROOFTOP",
"viewport" : {
"northeast" : {
"lat" : 37.4234129802915,
"lng" : -122.0827425197085
},
"southwest" : {
"lat" : 37.4207150197085,
"lng" : -122.0854404802915
}
}
},
"place_id" : "ChIJ2QHGpW-7j4ARe7z3NxQzggI",
"plus_code" : {
"compound_code" : "CWC8+R9 Mountain View, CA, USA",
"global_code" : "849VCWC8+R9"
},
"types" : [ "street_address" ]
}
],
"status" : "OK"
}
Next, create a test.php file on your webpage, all by itself. Just this: -
<?php
$json = file_get_contents('https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&key=MY_KEY_HERE');
echo $json;
Then, browse to that file and check it dumps the same JSON.
(Note if you’re doing this in your CakePHP app it’ll need to go in webroot
[or equivalent].)
Then do the JSON decode, then get the lat lng and echo that.
Next, copy that exact code into to submit side of your controller, so it still pulls 1600 Amphitheatre Parkway
regardless of what is entered on the form, and debug that result.
Then pull live data.
I apologise if you’ve already done all that, or a similar process, but first you need to be sure your API is sound and behaves on your site. Also factor in that on the Credentials page Google says any change can take up to 4 hours to implement (but I’ve also found them to be immediate).
Harden your key, lock it down to your IP and webpage IP. If you’re running CloudFlare you’ll need to use HTTP referrers (which don’t always behave for me, and need separate rules for HTTP & HTTPS) - or turn CloudFlare off. After hardening test again! And don’t forget to delete your test.php!!