Google Maps Purchased Plugin - Is it possible to place Custom Fields from map in another location in

I need to know how to do the following:
1. Place address used in map in another place on page template.
2. Customize the Details box for each icon. For example, change the word "Posts" to "Sites"
3. Do not display description box below map, but still show posts associated to map icon once you click on it.

I know how to edit the php etc.
Thanks!
Lena

  • Vladislav

    Hello,

    The first point, reusing the existing map, is entirely possible using our shortcode. If you want to use it in the theme template, you can use the do_shortcode PHP call to process it. There is a couple of ways you could go about doing this, depending on whether the map has been associated with a post or not. If it has, you can make use of the query attribute, e.g. like this:

    <?php echo do_shortcode('[map query="p=471"]'); ?>

    ... where 471 is an example of the post ID your map has been associated with. Alternatively, you could use the map ID directly, like so:

    <?php echo do_shortcode('[map id="1"]'); ?>

    You can get the map ID and the entire shortcode you want to use by finding the map you want to use in the insert map interface, then inserting it into a post. You can then just copy that shortcode and paste it in the do_shortcode call.

    As for not showing the description box below the map, currently your best bet could be hiding it. You can do this by adding a bit of custom CSS, e.g. like so:

    .agm_mh_marker_list { display: none; }

    You can add this into the "Additional CSS" field in Settings > Google Maps.

    Lastly, about customizing the the Details box, I'm not sure I got what you meant by that. Could you please be a bit more specific? Generally speaking, though, pretty much all the strings in the plugin are exposed for translation, so you could change any one of them by generating a custom translation to English. Alternatively, you could also use the Ultimate Branding plugin to change the language instead.

  • dandi-admin

    Thank you for your quick response, I appreciate it, unfortunately I didn't get the answers I was looking for. Let me try to rephrase as I see the confusion.

    First of all, I understand that I can hide the marker list with CSS, thank you for clarifying that that is the only way.

    As for the part about the shortcode. I am actually already using the shortcode feature which is nice, but my main goal was to extract info being use for the map in another location, not in a map. To be more specific, I have a map at the bottom of a post, but I want to list the address text at the top of the post and didn't want the client to have to input it twice. I thought there might be a way to display the "description" and "title" from the map details separate from the map itself. I realize that is already happening with the marker list, but is there a way for me to dissect those pieces separately with php to place them where I need them?

    As for the last part about customizing the description, I do not wish to translate it, I just wanted to perhaps delete the name "posts" or give that a more descriptive name. To be clear, I am talking about the heading "posts" that then lists the posts associated to that location. I can keep searching where that is being called in the php plugin files.

    I really appreciate your timely responses.

    Thanks!
    Lena

  • Vladislav

    Hello,

    @Lena, thank you very much for the clarification, I think I get much better now what you're after. If you're OK with putting together some custom code, you can make use of the plugin's model class to get to the map data you need. Internally, each map has an array of markers, and each marker is a hash containing keys for icon, title, body and location. Having this in mind, you could e.g. list all markers for a map in a list using something like this:

    <?php
    $map_id = 1;
    if (class_exists('AgmMapModel')) {
    	$model = new AgmMapModel;
    	$map = $model->get_map($map_id);
    	$markers = !empty($map['markers']) ? $map['markers'] : array();
    
    	if (!empty($markers)) {
    		echo '<ul>';
    		foreach ($markers as $marker) {
    			echo '<li>';
    			echo $marker['title'] . '&nbsp;' . $marker['body'];
    			echo '</li>';
    		}
    		echo '</ul>';
    	}
    }
    ?>

    The $map_id variable at the top is the ID of the map we want to use. Of course, using the same class we could get to any other kind of map, including querying the posts for associated maps. The class itself is located in lib/class_agm_map_model.php and is fairly commented, so if you need to make use of some other methods perhaps having a peek there could help - or I can help with some sample code, too.

    As for the javascript interaction, that is possible too (also a very good point, thank you @oscar_rottink - the plugin exposes quite a few custom jQuery events, and we also use them internally, in our add-ons. If you lean more towards the javascript approach, the most basic event you may want to listen for is "agm_google_maps-user-map_initialized", which is fired once per map on the page. You could subscribe to it e.g. like this, for a map with ID 49:

    <span id="marker-output"></span>
    <script>
    (function ($) {
    $(document).on("agm_google_maps-user-map_initialized", function (e, map, data, markers) {
    	if (!markers.length) return false;
    	if (!data.id || parseInt(data.id, 10) !== 49) return false;
    	$("#marker-output").html(markers[0]['title']);
    });
    })(jQuery);
    </script>