When Google introduced a requirement for an API key before a map could be embedded into a page, it introduced a measure of complexity that simply stopped many from using the service. In this article we'll provide you with the Bing API-key-free alternative. A simple shortcode will return a Bing Map into your WordPress post or page with shortcode.
The Bing alternative isn't as feature rich as the Google alternative, and sadly, it doesn't support a marker unless the map is rendered programmatically.
The Result
The shortcode of [bm_bing_map latitude="-33.85703468676193" longitude="151.1931205078125"]
returns the following:
You may return an aerial view (and include or exclude labels), or alter the level (or scale). As you can tell from the above, the map doesn't support address geocoding out-of-the-box. Instead, you'll have to use a latitude and longitude. You may obtain these details from the Bing Embed page, or via a Google Map URL.
If you required reverse geocoding you should add a few lines into the code to obtain and cache the coordinates; there are plenty of services to choose from, including Google and Bing (although if you had a Google API Key you would be better served by using the Google Map embed code).
Pictured: You may also copy the latitude and longitude directly from a Bing map.. Despite the lack of reverse geocoding, the latitude and longitude does provide a consistent and accurate result.
To return an aerial view of Sydney's GPO we'd use the shortcode of [bm_bing_map latitude="-33.85703468676193" longitude="151.1931205078125" aerial="1"]
. By default the labels are shown but you may exclude them with labels="0"
. In this example we'll also zoom out and show a smaller scale map with level="14"
(the shortcode defaults to a level of 17). The result:
The margin above and below the map iframe may be altered with margin="30"
.
The Shortcode Function
Copy and paste the WordPress function into your theme's functions.php
file or, if you sensibly have one installed, your custom functions plugin.
If you require shortcode to work in a sidebar widget, you'll have to enable the functionality with a filter. If you're using our custom functions plugin, you'll have that feature enabled by default.
Shortcode Attributes
A small number of shortcode attributes apply.
latitude and longitude
latitude
and longitude
of the reference point. Obtain via Google Maps or Bing Maps.width and height
width
and height
of the map.aerial
aerial
is the 'satellite-style' aerial photograph, rather than a map. If an aerial photograph is returned the label
option is made available.labels
labels="0"
.level
margin
margin
alters the margin above and below the map. Defaults to 30px.Conclusion
We're considering including a feature-rich map feature into our Elementor plugin, but we'll get some feedback from users before we push ahead. If we did build the simple feature we'd certainly include a reverse geocoding function so the latitude and longitude wouldn't be required... but this would likely require we build it to utilise Google's service (thus requiring a Google API Key). If clients have a specific need, please let us know.
Download
Title: Bing Map Shortcode
Description: Returns an embedded Bing map into your post or page with shortcode. Various options apply.
Download • Version 0.1, 742.0B, zip, Category: WordPress Shortcodes