Forum
Store Finder connection between XML (Perch PHP) file and jQuery map
I have been following the help of some guys in the following thread re: making the connection between perch and my jquery Google map store finder code.
Paul Stone said:
So you've done the bit to allow the admin to enter the store locations in Perch?
If so, create a locations.php file with something like this in:
<?php header('Content-type: application/xml'); include('perch/runtime.php'); $dealers = perch_content_custom('Stores', array( 'skip-template'=>true, 'raw'=>true )); $xml_out = '<?xml version="1.0" encoding="utf-8"?><markers>'; foreach( $stores as $store ) { $xml_out .= '<marker name="'. $store['name'] .'" lat="' . $store['map']['lat'] .'" lng="' . $store['map']['lng'] .'" category="Store" address="'. $store['address'] .'" address2="'. $store['address2'] .'" city="'. $store['city'] .'" state="'. $store['county'] .'" postal="'. $store['postcode'] .'" country="'. $store['country'] .'" phone="'. $store['tel'] .'" email="'. $store['email'] .'" web="'. $store['website'] .'" />'; } $xml_out .= '</markers>'; print_r($xml_out); ?>
You will need to amend that based on your field names of course.
Then visit it in a browser and see if you get an XML file generated. As it has a .php file name Perch will process it and output an XML file to the browser for you. You should be able to amend this for JSON too, but I used XML.
Then in your JS, you need to tell the plug in that your filename has changed:
$(function() { $('#map-container').storeLocator({ 'dataLocation' : '/data/locations.php', // ... deleted other config for brevity }); });
The plug in doesn't care that the suffix is .php as the server gives it XML back anyway, but before that Perch will update it for you.
Does any of that help?
My trouble is that when I access my php file, as it should do it is showing an xml file but it is empty and hence no locations are showing up in my map.
Any ideas how I need to make perch output the stockist information in to this xml file for the map to pick up?
You're assigning the result of
perch_content_custom()
to$dealers
but then you're looping through$stores
.