Google Maps won't accept postcodes, only lat/long?
PermalinkFor some reason the Google map block seems to have stopped accepting postcodes. If you enter a postcode you get the dreaded marker-in-the-middle-of-the-sea blue map. It will however work fine if you input a latitude/longitude.
We're using the solution given by emparel here to add the API key in, and I'm sure in early September this was working just fine with postcode locations.https://www.concrete5.org/community/forums/usage/google-maps-not-wor...
Can anyone tell me what has changed, or more importantly how I can fix it? I would be extremely grateful.
However... it's still not working. The API key definitely is working. I originally added the key in to blocks/google_map/controller.php where it seems to be doing its stuff.
Now let's say I have a page with two Google Map blocks on it.
The first one, I'm using a postcode as the location. For some reason Google isn't interpreting this. If I look at the page source I see
<script type="text/javascript"> function googleMapInit2795() { try{ var latlng = new google.maps.LatLng(0, 0), balloonHtml = "", balloon; etc
But the second one I put a latitude/longitude in instead. This map shows up perfectly and the page source looks like
<script type="text/javascript"> function googleMapInit2616() { try{ var latlng = new google.maps.LatLng(53.6215837, -2.3938881), balloonHtml = "", balloon; etc
So it's something to do with the map block/Google not converting the postcode properly and just giving me 0,0.
What I know is I tried in 5.6.3.5 and the whole block was not workin. When I checked what Google map was sending back there was first an error about the API key and then another about the use of https. After I applied the fix I gave you, it worked fine with a zip code or a full address.
Before I made the change absolutely nothing was working and all attempts were rejected with the same API key and https error messages.
I'm not sure what's going on but maybe your website was originally using an older version and then you updated to 5.6.3.5 and the actual block is in the updates folder while you're looking at the root concrete folder? Just a theory but you might want to check
https://www.concrete5.org/community/forums/usage/google-maps-not-wor...
I will have another go with your solution. Can you confirm if I'm just supposed to overwrite that core file, or override it and if so exactly which directory the override is meant to be in?
Thank you!!
On the other hand that legacy version of C5 has reached end of life and no more support is planned for it so I don't think there's going to be any updates in the future and directly editing the file should be fine.
Another possibility would be the bring the code from that file directly to an override for the block controller itslef. So you would just put it in the root block folder in a folder named google_map and name it controller.php and make the proper modification to get it working.
If really nothing works for you, feel free to reach out by private message and provide me with access to your site and I can have a look for you in the morning if you want.
I'm not getting very far, even with resaving the maps, clearing the cache etc. It still doesn't seem to like US zip codes or UK postcodes, yet coordinates are accepted fine.
I am probably doing something stupid! I will sleep on it and if I can't figure it out tomorrow I might end up messaging & asking you to take a look - that's really nice of you to offer thanks.
Actually due to changes in how Google Maps work nothing should be working, not even full addresses.
Here's how to fix it.
Open the file concrete\core\controllers\blocks\google_map.php to edit it.
Normally that's where you should have added the fix to include your API key.
If you haven't, start by modifying line 70 to add your API key like this
You will notice that I also removed the sensor setting because it is deprecated and there is a deprecation notice from Google in your browser's console when keeping it in place.
Then go down to line 156 and 157 where you will see these 2 lines (inside the function lookupLatLong())
We needs to modify the first line to use https instead of http. And we need to modify the second line to use your API key.
Modify them like this:
Everything should work as expected now.