How to create a View to show an Open Street Map containing all markers
- This topic has 7 replies, 2 voices, and was last updated 1 hour, 45 minutes ago by
JonS.
-
AuthorPosts
-
March 22, 2025 at 6:24 PM #47896
JonS
ParticipantI've gone through the tutorial over and over again here:
https://docs.metabox.io/tutorials/display-listings-on-map/
but I just can't get it to work. I've also searched all through the forums but nothing here.
I keep thinking this must be both easy and something loads of people need and have done.
I have a custom post which has custom fields. One of these is map_location and it's all working perfectly in the backend where I can add the marker, drag it on the map, etc. and it stores it. I've even got it to show the map on the single page where the marker for that record is correctly positioned.
But I need to have a map in various places around the site to show all the markers so the logical method is to have an MB View and use the shortcode to put it wherever I want.
Can anyone please help me? It's driving me mad!
March 24, 2025 at 9:47 PM #47907Peter
ModeratorHello Jon,
There is a section in the tutorial that helps you use Views to show all markers on a map
https://docs.metabox.io/tutorials/display-listings-on-map/#32-method-2-using-mb-viewsif you want to use the PHP code, you can create a shortcode and wrap the PHP code inside the shortcode. Then you can add the shortcode to many places on your site. Please follow the documentation
https://docs.metabox.io/tutorials/display-listings-on-map/#32-method-2-using-mb-viewsMarch 24, 2025 at 9:57 PM #47908JonS
ParticipantThanks for your reply, Peter. That is the tutorial I've gone through in great detail multiple times but I just get a blank area where the map should be shown. I've set it all to use the custom post type I created. The field is all working fine. It should be so simple to have a map showing the markers but there's nothing.
March 25, 2025 at 9:41 PM #47913Peter
ModeratorHello Jon,
Please share your site admin account by submitting this contact form https://metabox.io/contact/
and let me know steps that you do you on your site, where I can see that. I will take a look.March 25, 2025 at 11:07 PM #47916JonS
ParticipantThanks Peter.
I've set you up with an admin login and sent the details via the contact form.
All the best
Jon
May 8, 2025 at 8:39 PM #48202JonS
ParticipantThanks to Peter for sorting me out with this.
One other quick thing I'm struggling with.
The tooltip popup shows the title and address (perfect) but I also want to show a link to the single page for that location.
What is the variable I should be calling...
location_on_map.url (url is wrong, what should it be?)
I hope that makes sense.
One last thing... can I stop the first location's tooltip from automatically showing? I just want to show the markers on the map and then, when one is clicked, have the tooltip appear which includes a link to that location.
Many thanks in anticipation.
May 8, 2025 at 11:22 PM #48209Peter
ModeratorHello Jon,
If you are using MB Views to output the map field, you should add another attribute to the data items and assign it to the post URL (permalink). Then add the URL to the popup in the JavaScript code. Below is an example:
{% set restaurantsArray = restaurantsArray|merge( [ { 'longitude': 'latitude': 'address': 'title': 'icon': 'url': post.url } ] ) %}
marker.bindPopup( '<b>' + location_on_map.title + '</b><br>' + location_on_map.address + '<br><a href="' + location_on_map.url + '">Go to Page</a>' ).openPopup();
Note: supporting more customization code is beyond our scope of support. If you are not able to complete the task, we offer a customization service for an extra fee. Please contact us here https://metabox.io/contact/ for more details.
May 8, 2025 at 11:32 PM #48210JonS
ParticipantFantastic. That was the missing piece I needed. Thanks Peter, you're a star.
-
AuthorPosts
- You must be logged in to reply to this topic.