• Resolved hommealone

    (@hommealone)


    Is there any mechanism for dynamically including a map via a template file, where the location is a variable accessible in the template file?

    For example, is there any way to use a shortcode, where the address is entered as a parameter of the shortcode?

    Or any other way to do this? The address cannot be known ahead of time until the page is generated by the template file.

    Something like…

    
    // address was entered in an ACF text field
    $address = get_field('address');
    $shortcode = '[wpgmza id="1" location="' . $address . '"]';
    
    echo do_shortcode($shortcode);
    

    It would be great if this were possible!

Viewing 4 replies - 1 through 4 (of 4 total)
  • I’ll be watching. I’d like this as wel! Lat lng maybe?

    • This reply was modified 6 years, 10 months ago by rodge11.
    Thread Starter hommealone

    (@hommealone)

    @rodge11 :
    Latitude and longitude as additional parameter options would be nice, if they were building in more options; but harder to get a hold of by an ordinary user, so I wouldn’t want to rely on that as a substitute for a location address.

    Hi @hommealone , Hi @rodge11

    It’s not possible to do this using the shortcode directly,

    However, you could pass in a location like that, and then reference shortcodeAttributes on your map client side.

    You can get a reference to your map using WPGMZA.getMapByID(123) where 123 is the ID of your map. You can then access shortcodeAttributes there.

    You can use WPGMZA.Geocoder.createInstance() to get a geocoder, then call geocode with the address and callback like this:

    geocoder.geocoder({address: map.shortcodeAttributes.location}, function(results) {
    
    var marker = WPGMZA.Marker.createInstance({
     address: map.shortcodeAttributes.location,
     lat: results[0].lat,
     lng: results[0].lng
    });
    
    });

    Please note this will use a geocode request per page load.

    You might consider looking at some of the Add-ons we offer at http://wpgmaps.com, we offer support for scheduled imports and dynamic data sources, perhaps that’s what you’re looking for?

    Kind regards
    – Perry

    Thread Starter hommealone

    (@hommealone)

    Thanks Perry @perryrylance

    I’ll look into the options you mentioned and see if we can use any of them. Thanks for your response and this information.

    I hope that you might consider this request as an update in some future version of your plugin. It might be something that other people can use too.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Generating dynamic maps in template files’ is closed to new replies.