This plugin adds a Google Maps places field to the media attachment edit interface. This enables the saving of places as post meta along with the attachment (Facebook-style photo tagging of places).
- Google Maps API Key - The key must have the Javascript Maps and Places APIs enabled, and have an associated billing method.
- After installing and activating the plugin, visit Settings > Media Location to enter your Google API key.
- Open a media library image
- New fields will appear below the standard media library fields, including date and location.
- If the Google Places library is enabled, search by location in the "Location" field. Selecting a location will populate some hidden field data including the place name, coordinates, etc.
- Click "Save Location" to save the date and location data.
All location data is saved as meta_data for the attachment object.
The location data is available through a REST API endpoint:
media-location/v1/attachment/{attachment_id}
The endpoint accepts one parameter, the attachment ID. The parameter name is id
. If location data is saved, this endpoint will return the normal post object along with the following extra properties:
place_id
- The Google Places IDplace_name
- The Google formatted place nameformatted_address
- The Google formatted addresslatitude
longitude
data
(stored in the format specified by the WordPress install)
A repository method for retrieving place data is included in MediaLocation\Repositories\AttachmentRepository
. Example usage:
$location_data = (new \MediaLocation\Repositories\AttachmentRepository)->getAttachment($id);
The output of location data is currently expected to be handled entirely by the theme. Note: Google's license agreement specifies that the geolocation data must be used within Google Maps. The output of maps and any tagged location must be handled by the theme.
A lightbox-style gallery with location output is currently under development to be included with this plugin.