AppGeolocation Setup
How to install App-Geolocation
Download the plugin .zip file from your account page, then upload in your WordPress admin under Plugins => Add New => Upload. Do not unzip the file.
If you would prefer SSH/FTP, extract the contents of the zip file and upload the contents to your wp-content/plugins/ directory on your server.
Configuring App-Geolocation
Once you have activated the App-Geolocation extension, a new tab will show up in the AppPresser settings page for it. In your WordPress admin, click on the AppPresser icon in your admin menu, then click the Geolocation tab.
Create a Google Map API key
Click "GET A KEY" which will take you to Google Developers Console.
2. Enter your site's URL
2. Locate and click the "Google Maps JavaScript API" link from the list of APIs.
3. Near the top of the page, press the "Enable" button.
4. Do steps 2 & 3 above for "Google Static Maps API" as well
2. Click "Credentials" on the left. Click "Create Credentials", and choose API key. Choose "Browser" key, then continue with STEP 1 & STEP 2 above.
Settings
Show map on posts with geolocation data
Check this setting if you want to display a Google Map ™ on posts that have collected and saved geolocation data. If checked, the map will be appended to the post's post content and use geolocation data saved to the post meta.
Save user geolocation data
Check this setting if you wish to save user-provided geolocation data to the current user's user meta. The geolocation of the user's current location at the time of AppPresser app use.
Frequency to save a user's geolocation data
Set how often the user's geolocation should be updated, in various available time intervals.
Once you are happy with the settings, click the "Save Settings" button.
Using App Geolocation
After you configure your API key, you can now use the various App Geolocation shortcodes and features. The [app-geolocation] and [checkin] shortcodes perform different functions, please see usage information below.
Checkins
The checkin feature adds a checkin modal with a map and pin point(s) of the user's current location. There is a toolbar icon added to the top right to open the modal and there is also a new [checkin] shortcode for for checking into places. There are three options for check ins. All checkin options requires a user to be logged in.
- Places search (adds multiple pins of a Places business near user)
- Address checkin (displays one pin at the specified address)
- Checks user into location (saves users latitude and longitude)
Checkin Shortcode
Example:
To search for nearby business located in Google places omit the address parameter.
[checkin class="checkin-button" button_text="Checkin Here" place="Starbucks"]
To drop a pin at a specific address include the address parameter.
[checkin class="checkin-button" button_text="Checkin Here" place="Workplace" address="123 main street colorado"]
- class - adds a custom class to the button for styling.
- button_text - the text displayed in the button (default: Check In)
- place - Google places search adds pins if places found
- address - the address to drop a pin, checks user into this address
The address parameter will override the place parameter and drop a pin at the address supplied. Omit the address parameter and Places will search for locations close to the users location. A user can click a pin and then check into that place.
If you want to have the user checked into a specific address omit the place parameter.
App-Geolocation Hooks
appp_user_profile_fields
Type: Action | File: apppresser-geolocation.php | Since: 1.0.0
Hooks right after the "Geolocation" header so that you can add extra user profile fields.
Provided parameter:
$user_id
appp_before_geolocation_buttons
Type: Action | File: apppresser-geolocation.php | Since: 1.0.0
Hooks inside the output for the geolocation form, at the top, before the output of the inputs.
Provided parameter
$appp_atts
will be the attributes used on the shortcode in the post editor.
appp_after_geolocation_buttons
Type: Action | File: apppresser-geolocation.php | Since: 1.0.0
Hooks inside the output for the geolocation form, at the top, before the output of the inputs.
Provided parameter:
$appp_atts<p><code>$appp_atts
will be the attributes used on the shortcode in the post editor.
appp_after_process_geolocation
Type: Action | File: /inc/AppPresser_GeoLocation_Update.php | Since: 1.0.0
Hooks after the update or insertion of the post, with the new post ID
Provided parameter:
$post_id
active_plugins
Type: Filter | File: apppresser-geolocation.php | Since: 1.0.0 Located in: /plugins/app-geolocation/apppresser-geolocation.php
Allows you to intercept get_option( 'active_plugins' ) before our WooCommerce extension determines if WooCommerce is presently active.
Default value:
get_option( 'active_plugins' )
appp_geolocation_post_title_label
Type: Filter | File: apppresser-geolocation.php | Since: 1.0.0
Allows you to modify the text displayed with the label for the title field, when the post_title
shortcode attribute is set to true.
Provided value:
'<label>' . __( 'Title:', 'apppresser-geolocation' ) . '</label>'
appp_geolocation_post_content_label
Type: Filter | File: apppresser-geolocation.php | Since: 1.0.0
Allows you to modify the text displayed with the label for the content field, when the post_content
shortcode attribute is set to true.
Provided value:
'<label>' . __( 'Content:', 'apppresser-geolocation' ) . '</label>'
Checkin Hooks
There are two hooks during the creation of the checkin.
apply_filters( 'appgeo_checkin_post_filter', $checkin ); apply_filters( 'appgeo_checkin_meta_filter', $checkin_meta );
appgeo_checkin_post_filter
is to filter the checkin cpt and appgeo_checkin_meta_filter
is used to filter the checkin meta ( location data ).
Example:
appgeo_checkin_post_filter
function my_filter_checkin( $checkin ) { $checkin['post_title'] = 'custom title checking'; return $checkin; } add_filter( 'appgeo_checkin_post_filter', 'my_filter_checkin' );
appgeo_checkin_meta_filter
function my_meta_filter_checkin( $checkin_meta ) { $checkin_meta['place'] = 'Starbucks - the one on the moon'; return $checkin_meta; } add_filter( 'appgeo_checkin_meta_filter', 'my_meta_filter_checkin' );
Using Checkin Data
Now that users are adding checkins with location meta you can use this data. All checkins are a custom post type (checkin).
get_posts( array( 'author' => $user_id, 'post_type' => 'checkin') );
The location data is post meta. Post meta keys:
get_post_meta( $post_id, 'latitude' )
- latitude
- longitude
- place
- address
Default GPS Position Hook
In version 2.1.0, a default position was added in case the GPS has been disable from a user's device. You can use a hook to either set the default position or disable it completely.
Type: Filter | File: AppPresser_GeoLocation_Modal.php | Since: 2.1.0 Located in: /plugins/appgeo/inc/AppPresser_GeoLocation_Modal.php
Set your own position
function my_default_gps_position() { return array( 'latitude' => '46.8533701', 'longitude' => '-55.8090062' ); } add_filter( 'appgeo_default_position', 'my_default_gps_position' );
Disable default position
function disable_default_gps_position() { return true; } add_filter( 'appgeo_default_position', 'disable_default_gps_position' );
appgeo_map_images
If you would like to customize the marker images using with the [appp-map] shortcode you can create a directory on your site with replacement images.
To use the appgeo_map_images filter:
- Create a directory somewhere on your site such as in your theme folder or you wp-content/uploads folder
- Copy the images from the /wp-content/plugins/appgeo/images/ folder to your own folder
- Edit the files you copied with your photo editor
- Add the appgeo_map_images filter to your directory
- create a function that return a string of the URL path to your marker images
- You will want to add this function to the mu-plugins folder so it works regardless which theme you are using. If your WordPress install doesn't have a mu-plugins directory create one inside the wp-content directory. You can just create a new file named my-appgeo-map-images.php and paste the code below into it.
<?php // /wp-content/mu-plugins/my-appgeo-map-images.php /** * Used with the appp-map shortcode. * This will return the URL to my custom map markers * * @return string A url such as: http://mysite.com/wp-content/uploads/my-custom-markers */ function my_appgeo_map_images( $url_path ) { $my_folder_name = 'my-custom-markers'; $uploads = wp_upload_dir(); return $uploads['baseurl'] . '/' . $my_folder_name . '/m'; } add_filter( 'appgeo_map_images', 'my_appgeo_map_images' );
appgeo_map_images
If would like use overwrite the default center_lat and center_long used with the appp-map shortcode you can use the appgeo_map_coord filter
- Create a function that return an array of the lat and longs
- You will want to add this function to the mu-plugins folder so it works regardless which theme you are using. If your WordPress install doesn't have a mu-plugins directory create one inside the wp-content directory. You can just create a new file named my-appgeo-map-coord.php and paste the code below into it.
<?php /** * This will return my default lat and long to use * will all of my appp-map shortcode maps * * @return array */ function my_appgeo_map_coord() { $my_default_lat = '48.1282706'; $my_default_long = '-55.3150867'; return array( 'latitude' => $my_default_lat, 'longitude' => $my_default_long ); } add_filter( 'appgeo_map_coord', 'my_appgeo_map_coord' );