We are transitioning over to a new forum platform. Please post new issues there. Existing threads will be dealt with here unless you choose to move them over. Visit the new forum

Forum

Thread tagged as: Question

Multiple locations on one map?

I need to able to set up a map to accept multiple individually numbered flags - with the corresponding flags also shown next to a list of their associated addresses (displayed alongside the map).

The client's old site has this in place (using a Google map), but I cannot make head nor tail of the masses of code used to achieve this. And, of course, I would like to keep everything within Perch, if at all possible.

The client needs to be able to add/delete product installers nation-wide.

Can such a thing be done? I already have a Perch map in place on the new site, but obviously at this stage it won't accept any more than one address.

Jonathan Wilson

Jonathan Wilson 0 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

I don't think anything gets you around the fact that you'll need to either write the map code or find something that does it for you. That might be the best place to start.

If you had a map that could, for example, display points based on a JSON data file, that would be ideal.

Then it's a case of capturing and managing the content, which is where Perch comes in. I'd have a multiple item region of Installers, with whatever information you need to store about them, including a map for the location. The map in this instance would be used to capture the co-ordinates only.

You could then use perch_content_custom() to output the data in the format the display map needs.

So the first action is to find a map library that

  1. Looks good for your site
  2. Plots multiple points
  3. Reads the data for the points form something like a JSON file

Ok, I found a solution from Google themselves - they have a number of Javascript options for various map functions, including multiple locations and it took next to no time at all to make it play nicely with Perch. The only slight wrinkle is the the client will have to be forearmed with the appropriate lat/long coordinates each time they want to add a new location.

Drew McLellan

Drew McLellan 2638 points
Perch Support

You can use the Perch map field type to capture those, as described.

Well, I've played around for ages, but I'm stumped, sorry... How would I capture just the lat/lng data from the map field? All I need is for perch_content_custom() to dump those coordinates into this template:

[lat.number, lng.number],
Drew McLellan

Drew McLellan 2638 points
Perch Support

The map will capture more than that, but it should expose the lat and lng when you get the content back with skip-template.