Duplicate maps on a page

Hi,
i want to display the googlemap exist on properties page to a different page with different size

I couldn’t able to find the map id or shortcode that i can get so i can add on my other page.

Hi,

​Please send more details about this question, and we will do our best to help you.

If you want to duplicate the map, you can do it by overwriting the template using this doc How to customize templates - HivePress Help Center

@andrii i created a template but i don’t know how to add that template to page or view that template.

@andrii After reading my last reply, also tell me how to properties page (all listings) Displays map block using shortcode.
image

This page doesn’t use a shortcode, it’s built with blocks, if you mean duplicating map at the bottom of the listings page there are 2 ways to do this:

  • By overriding the Listings page template in HivePress/Templates
  • By using custom code snippets for the hivepress/v1/templates/listing_view_page hook

P.S. If you purchased a theme or extension, please enter the license key in the forum profile settings, this will enable the Premium Support badge and ensure a 24-hour turnaround time.

can you please give me an example, how i can duplicate the map only in wordpress page ?

also when i use code snippets i get following error:
Parse error: syntax error, unexpected token “namespace” in wp-content/plugins/insert-php-code-snippet/shortcode-handler.php(99) : eval()'d code on line 8

Hi,

Sorry for the inconvenience, but customization is beyond our support scope - it includes fixing bugs and guidance about the available features Support Policy | HivePress

If customizations are required for your site, please try customizing it using the collection of code snippets Search · user:hivepress · GitHub and other developer resources, or consider hiring someone for custom work https://fvrr.co/32e7LvY

Sir I don’t want to customize any map or anything, I’m asking a simple question, How can i copy the same layout of the map to another page?

Example:
in /properties (Listing) page, there’s map showing in bottom (in a layout), i want to copy that only map layout and paste it to another page, so the map appearing on listing page will appear on another page also. i don’t want to customize the map.

Unfortunately this requires customizations, since this is beyond the available options - there’s no global Map block or shortcode that can be placed on other pages. The Map block on the Listings page is template-specific, it’s loaded within the listing query context so it shows the current listing markers, if you place it on another page the map will be empty. For example you can try placing this HTML on any other page in WordPress/Pages:

<div class="hp-map" data-component="map"></div>

HivePress will render a map via its JS code, but as noted it will be empty by default.

can you please tell me that js code which i can place on another page and same content appear on map.

Hi,

Sorry for the inconvenience, but customization is beyond our support scope - it includes fixing bugs and guidance about the available features Support Policy | HivePress

If customizations are required for your site, please try customizing it using the collection of code snippets Search · user:hivepress · GitHub and other developer resources, or consider hiring someone for custom work https://fvrr.co/32e7LvY

I am trying to place a map on a different page through shortcode using the following code.
but i get error HivePress\Geolocation\Blocks\Listing_Map_Block [NOT FOUND]
can you please tell me how to define $listing variable or the correct location of listing_map.

function display_listing_map( $atts ) {
    $map_html = '<div class="widget hp-map" id="map" data-height="200" data-max-zoom="18" data-component="map"></div>';
    $listings = HivePress\Geolocation\Blocks\Listing_Map_Block::get_listings_data(); // get listings data from your PHP code
    $markers = array();

    foreach ( $listings as $listing ) {
        $address = $listing['address'];
        $latitude = $listing['latitude'];
        $longitude = $listing['longitude'];

        // create marker object with listing data
        $marker = array(
            'lat' => $latitude,
            'lng' => $longitude,
            'title' => $listing['title'],
            'url' => $listing['url'],
            'image' => $listing['image'],
            'address' => $address,
        );

        // add marker to array
        $markers[] = $marker;
    }

    // generate JavaScript code to add markers to map
    $markers_js = '';
    foreach ( $markers as $marker ) {
        $markers_js .= "var marker = L.marker([{$marker['lat']}, {$marker['lng']}]).addTo(map);\n";
        $markers_js .= "marker.bindPopup('<div class=\"map-popup\"><a href=\"{$marker['url']}\" target=\"_blank\"><img src=\"{$marker['image']}\" /><h3>{$marker['title']}</h3></a><p>{$marker['address']}</p></div>');\n";
    }

    // generate JavaScript code to initialize map
    $map_js = "var map = L.map('map').setView([{$markers[0]['lat']}, {$markers[0]['lng']}], 10);\n";
    $map_js .= "L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
                    maxZoom: 18,
                    attribution: 'Map data &copy; <a href=\"https://www.openstreetmap.org/\">OpenStreetMap</a> contributors, ' +
                        '<a href=\"https://creativecommons.org/licenses/by-sa/2.0/\">CC-BY-SA</a>, Imagery © <a href=\"https://www.mapbox.com/\">Mapbox</a>',
                    id: 'mapbox.streets'
                }).addTo(map);\n";
    $map_js .= $markers_js;

    // add JavaScript code to map HTML
    $map_html .= "<script>jQuery(function($) { $map_js });</script>";

    return $map_html;
}
add_shortcode( 'alisting_map', 'display_listing_map' );

Please describe the required result and we’ll provide some general guidance, it can be useful if you’re familiar with PHP. Unfortunately we can’t help with implementing specific customizations, we support existing features only (by fixing bugs and providing guidance).

The code snippet seems to be incorrect, for example there’s no get_listings_data method in the block so it’s impossible to call it this way hivepress-geolocation/class-listing-map.php at master · hivepress/hivepress-geolocation · GitHub

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.