Forum

Thread tagged as: Problem

Map fieldtype issues

Hey,

I have set up an API key with Google, and included it in Perch in the recommended way, using config.php:

define('PERCH_GMAPS_API_KEY', 'xxxxxx');

As I understand from your code in Perch's Public Maps JS file, you seem to be loading a static map which is a fallback if the dynamic JS map. Neither are loading on the front end.

Testing the setup, I removed the API key, and the map would not load in the Perch back end, nor in the front end. Adding the API back in meant the Perch back end map preview worked, but the front end still did not load.

I see that Perch generates a script loading tag like this:

<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=xxxxxx"></script>

There is no callback script in this url as I would normally run on a web page, to initialize the map once the JS has been loaded from the google server. Could this be the reason why the JS map isn't loading (I am not using a custom JS map file).

Also, here is the markup generated for the static map by perch:

<img id="cmsmap139-1" src="//maps.google.com/maps/api/staticmap?key=xxxxxx&center=51.5301219,-0.09480780000001232&size=400x300&scale=2&zoom=16&maptype=map&markers=color:red|color:red|51.5301219,-0.09480780000001232" width="400" height="300" alt="51.530135,-0.0946735">

Also, below the static map, here is the outputted markup:

<script type="text/javascript">/* <![CDATA[ */ if(typeof CMSMap =='undefined'){var CMSMap={};CMSMap.maps=[];document.write('<scr'+'ipt type="text\/javascript" src="/perch/core/assets/js/public_maps.min.js"><'+'\/sc'+'ript>');}CMSMap.maps.push({'mapid':'cmsmap139-1','width':'400','height':'300','type':'map','zoom':'16','adr':'51.530135,-0.0946735','lat':'51.5301219','lng':'-0.09480780000001232','clat':'51.5301219','clng':'-0.09480780000001232'});CMSMap.key='xxxxxx';/* ]]> */</script>

As you can see I have hidden the API key just for posting on this forum.

In the Maps API Console, I can see there are requests being made, strangely they show a 200 response, which differs from the 403 I'm getting from in-browser console on the site itself.

Any tips would be greatly appreciated, thanks.

Adam Menczykowski

Adam Menczykowski 1 points

  • 5 years ago

Here is my Diagnostics report:

Perch: 2.8.31, PHP: 5.4.45, MySQL: mysqlnd 5.0.10 - 20111026 - $Id: c85105d7c6f7d70d609bb4c000257868a40840ab $, with PDO
Server OS: Linux, cgi-fcgi
Installed apps: content (2.8.31), assets (2.8.31), categories (2.8.31)
App runtimes: <?php $apps_list = array( 'content', 'categories', );
PERCH_LOGINPATH: /perch
PERCH_PATH: /homepages/22/d415536610/htdocs/sardine/public/perch
PERCH_CORE: /homepages/22/d415536610/htdocs/sardine/public/perch/core
PERCH_RESFILEPATH: /homepages/22/d415536610/htdocs/sardine/public/perch/resources
Image manipulation: GD
PHP limits: Max upload 64M, Max POST 64M, Memory: 256M, Total max file upload: 64M
F1: 2edba60ed1f613d6dd804feb202456a2
Resource folder writeable: Yes
HTTP_HOST: sardine.london
DOCUMENT_ROOT: /kunden/homepages/22/d415536610/htdocs/sardine/public
REQUEST_URI: /perch/core/settings/diagnostics/
SCRIPT_NAME: /perch/core/settings/diagnostics/index.php

Also of importance, I have added all the domains that the maps api will be loaded through, via the API Console on Google's site. I have added the trailing domainname.com/* as they instruct.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Have you verified your maps key is working?

It is hitting the API and returning a 200 according to their console, yes.

Drew McLellan

Drew McLellan 2638 points
Perch Support

But you're seeing a 403, are you not?

Yes correct, the 4xx errors aren't showing up in the Google API console though.

OK

So Going into the Google API Manager, I had to enable 'Google Static Maps API'.

Now I am getting successful static maps on the front end.

However, I am still not getting an interactive map. I may need to find out what API needs to be enabled to get this working, as there a number of different MAP API's that you can enable on the Maps Manager.

Perhaps the reason the JS interactive map is not getting loaded is because Perch doesn't set a callback function on the url to load the JS map?

Drew McLellan

Drew McLellan 2638 points
Perch Support

It has to be configuration or environment. If it was the code then it wouldn't work for anyone else.