How to create a View to show an Open Street Map containing all markers

Support MB Views How to create a View to show an Open Street Map containing all markers

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #47896
    JonSJonS
    Participant

    I'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!

    #47907
    PeterPeter
    Moderator

    Hello 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-views

    if 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-views

    #47908
    JonSJonS
    Participant

    Thanks 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.

    #47913
    PeterPeter
    Moderator

    Hello 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.

    #47916
    JonSJonS
    Participant

    Thanks Peter.

    I've set you up with an admin login and sent the details via the contact form.

    All the best

    Jon

    #48202
    JonSJonS
    Participant

    Thanks 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.

    #48209
    PeterPeter
    Moderator

    Hello 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.

    #48210
    JonSJonS
    Participant

    Fantastic. That was the missing piece I needed. Thanks Peter, you're a star.

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.