Google Maps won't accept postcodes, only lat/long?
Permalink
Hi, I have a site I help to run on 5.6.3.5 (yes, I know it's old but it is for a community ramblers club and those who edit it are not keen on too much change!)
For 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.
For 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.
Thanks for the reply, I really appreciate it.
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
But the second one I put a latitude/longitude in instead. This map shows up perfectly and the page source looks like
So it's something to do with the map block/Google not converting the postcode properly and just giving me 0,0.
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.
There is something I don't understand. You said you are using Concrete5 5.6.3.5. In that version the block's controller is empty and extends a core class, the one I indicated. So I don't understand how you added your API key there.
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
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
oh one mroe thing, after you fix the code how I showed you, you have to put any pre-existing map in edit mode and save again because that's when the block converts zip code and addresses into coordinates
If you see my first post, I did exactly this back in Sept:
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!!
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!!
I didn't try to override it so I'm really not sure how that would work.
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.
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.
Yes absolutely it won't be updated again (hopefully eventually converted to a much newer version when I can spare the time!) so it would be fine to change the original file, I was just concerned I was maybe somehow getting a conflict with the previous override to the controller.
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.
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.
good luck :)
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.