mustardbees / cmb_field_map Goto Github PK
View Code? Open in Web Editor NEWGoogle Maps field type for Custom Metaboxes and Fields for WordPress
Google Maps field type for Custom Metaboxes and Fields for WordPress
I added cmb_field_map to pages, where to goal was to have the option for some pages to show a map. The pages in question are not known beforehand so I need a way to check if the be rendered or not. Since once attached to pages all pages will have coordinates information (when saving), are you planning on adding a switch to control this?
I can easily do it with another cmb2 field for hiding the information in the front-end, but im just wondering if there's a cleaner approach to that.
Thanks.
Hi,
Thank you for this useful plugin.
If I am not missing something, I suggest adding the following to the readme file.
When adding cmb_field_map folder to - let's say - "my_theme_folder/cmb_plugins/", only setting a require_once order would not be sufficient as the JS & CSS files won't be enqueued properly.
Indeed, the following constant points towards WP's plugins folder.
// Useful global constants
define( 'PW_GALLERY_URL', plugin_dir_url( __FILE__ ) );
Source: https://github.com/mustardBees/cmb_field_map/blob/master/cmb-field-map.php#L12-13
Instead, I would need to define it this way in my case:
// Useful global constants
define( 'PW_GALLERY_URL', get_bloginfo('template_directory') . '/cmb_plugins/cmb-field-map/ );
NB: This is also applicable to your other CMB plugins.
Best
Hi,
Thanks for nice plugin
I found that marker is not showing
by editing script.js line 39 to
`
marker.setPosition( latLng );
if ( latitude.val().length > 0 && longitude.val().length > 0 ) {
//marker.setPosition( latLng );
}
`
make it working
I hope this help
Thanks
In my first post map are showing exactly but the next post map are not showing// please help me..waiting for your positive response.
thanks
my map coding in (index.php): -
<script>
<?php $maddr = get_post_meta(get_the_ID(),'event_map',true);?>
function initMap() {
var myLatLng = {lat: <?php echo $maddr['latitude']; ?>, lng: <?php echo $maddr['longitude']; ?>};
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 10,
center: myLatLng
});
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
title: '<?php echo the_title();?>'
});
}
</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAh4eG0CZSzobg49GlkbM1Cvsammyz7hSg&callback=initMap">
</script>
cmb2 coding: -
$eventsfield -> add_field(array(
'name' => 'Event Location In Map',
'id' => 'event_map',
'type' => 'pw_map',
'split_values' => true,
));
I use CMB often as it is one fantastic web development tool for WordPress. I just learned that there are third party resources. I know how to include the array for the map in example-functions.php (which will be of course renamed), but where should I put the files such as cmb-field-map.php, the css and js folders? On the same level as the CMB folder?
I'm trying to put it inside theme but doesn't work.
CMB works ok.
Others metaboxes are showing fine.
This one doesn't show map and reviewing with Firebug find this error inside script.js called:
You don't have permission to access ...addresstomytheme.../inc/metaboxes/cmb_field_map/js/script.js
on this server.
When I comment this line define( 'PW_GOOGLE_MAPS_URL', plugin_dir_url( FILE ) ); and replace by define( 'PW_GOOGLE_MAPS_URL', trailingslashit( get_stylesheet_directory_uri() . '/inc/metaboxes/cmb_field_map/cmb-field-map.php' ) );
I found this error: Fatal error: Call to undefined function add_filter() in ...addresstomytheme...\inc\metaboxes\cmb_field_map\cmb-field-map.php on line 30
Just wondering if you could provide additional documentation for the front end. I saw one method submitted in a closed issue, which appeared to work for mapping a single point. I would love to see how you might use this in a query to show multiple points on a map.
Great addition, love what you've done!
Adding the 'required' attribute doesn't affect this field. :(
// Event Coordinates
$bo_open->add_field( array(
'name' => __('Event Mapping Location', 'bo_cmb2' ),
'desc' => __('Regardless of the number of properties, pick a spot on the map to represent the "center" of your event)', 'bo_cmb2' ),
'id' => $prefix . 'location',
'type' => 'pw_map', //only does lat+long, per https://github.com/mustardBees/cmb_field_map/issues/22
'split_values' => true, // Save latitude and longitude as two separate fields
'attributes' => array(
'required' => 'required',
),
) );
Hi guys!
Great plugin mustardBees, I use it on all my wordpress projects related to an address somehow.
For my current project, I need people to add a custom post type object via the front-end.
They'll be able to add their car for rent online. I'd love to use your plugin in this front-end part as well so the user can select his address easily.
How can I do that?
Thanks!
I wish i had time and knowledge to fork this to add a setting page or something like that to provide the possibility to define the starting point of the map (currently UK). For now i'll just modify the file ^^
Fatal error: Cannot redeclare class PW_CMB2_Field_Google_Maps in /home/site/public_html/wp-content/plugins/cmb_field_map-master/cmb-field-map.php on line 16.
Can you provide 2 lines installation guide for this plugin?
I load cmb2 through my theme folder.
require_once 'cmb2/init.php';
and the cmb_field_map as a plugin in the plugin directory.
I put the pw_map field but is not working. I notice that the cmb_field_map js and css files is not being loaded so I am wondering if I am missing something with the installation.
Thanks in advance
If I'm reading https://developers.google.com/maps/terms#10-license-restrictions correctly, we should not store the latitude/longitude coordinates longer than 30 days: http://cl.ly/3Q3n1l113x0m
and we should display these things: http://cl.ly/2R3J3r3a2B2Z
and display the text "powered by Google" somewhere: http://cl.ly/2S000B3M092m
Hi,
Really love this class - however, there is a small bug: when split_values=true, the two input (hidden) fields created for latitude and longitude receive the exact same ID. This is not allowed in HTML - but worse, it prevents using these fields for various additional JavaScript validations, extrapolations, etc.
I solved this by editing cmb-field-map.php and adding 'id' => $field->args( 'id' ) . '_longitude' (for example) to the $field_type_object->input array... so it's a simple fix...
Thanks,
Bira
Hello,
I just discovered this field and want to know if this field supports use in Group. Is this field Repeatable? Documentation of this field does not reveal this info, hence asking.
Waiting for your reply...
Cheers,
Ruturaaj.
As per this article. This plugin no longer works until it's updated to allow an API key to be added.
https://googlegeodevelopers.blogspot.co.uk/2016/06/building-for-scale-updates-to-google.html
Great plugin though, I hope to be able to continue using it!
Change the placeholder for 'location' from 'enter a location' to something a little more detailed. i.e. 'enter an address / postcode / lat long'.
I had no idea what type of format this was expecting.
Hi,
I really love your pluign, hope @jaredatch include your code in the framework :)
Ok, this is my problem. I have the map inside a hidden div, is a tab actually, so when I click in the tab where the map is the "point" of the location is not in the center it moves to the top-left corner of the iframe, searching for a solution I found this script: http://stackoverflow.com/questions/4528490/google-map-v3-off-center-in-hidden-div
But seams do not work, any idea of how can I fix this?
Thanx.
The plugin works great with CMB2 boxes on posts (need to use PR #45 + an api key), but it does not work with CMB2 boxes on terms. The value does not save.
The map also loads very narrow:
https://cloudup.com/cmXV7hN-IZP
EDIT: Turns out, it's setting split_terms to true that's not updating the split values. It works fine when split_values is false.
I see that I can render the map in the admin, but is there a function to use for rendering it on the public viewable page?
I am new to the whole Github experience and am working with the cmb_field_map but I for the life of me cannot add driving directions to the meta boxes php
API Key Is required in our instance. I was able to fix this by hardcoding the API key in the Google Maps script enqueue. It might behooves to add this as an option or setting in the admin :)
Hi i cant find any documentation that tells me exactly wich is the type of field that defines the map
array(
'name' => 'Mapa',
'desc' => 'Especifica con detalle la dirección del comercio',
'id' => $prefix . 'direccion2',
'type' => '???',
),
Hello everyone, I have not had any problem to get the latitude and longitude from a CPT reading all your comments and the problems that arose.
But when it comes to wanting to get those coordinates from a map that is located on an administrator page that i created, i'm not able to.
I have tried it this way, and it returns a blank space:
$mapGPSlat = myprefix_get_option('location-ga_latitude');
$mapGPSlong = myprefix_get_option('location-ga_longitude');
I hope you can help me.
A greeting.
So far the input box above the map serves to search for a place's latidude and longitude.
To make the plugin even easier and more flexible to use,
To achieve the first point, I found this script example that may be useful (see source code) http://www.geocodezip.com/v3_GoogleEx_geocoding-reverse2postcodeA.html [found through http://stackoverflow.com/questions/17830686/how-to-get-city-from-coordinates]
For the second point, location name's metadata could be saved and loaded through another hidden input field, to avoid another external request.
Well I have never used GoogleMaps API so far, and can't adapt geocodezip.com's straight away. I'll see if I can submit something later on.
I have forked the plugin at https://github.com/gareth-gillman/cmb_field_map and extended it with:
I am also going to hook into Google API key and check if the key is valid before saving to the DB (if I can).
Happy to pull request if Phil wants it in his plugin, using it on my own project so thought be useful to others since the google api change
Once created and set the location in the map i cannot find the way to reset the field.
Thank you very much!!
Would it possible to add that it's possible to set default map location my wordpress filters or something? Now the default view is UK. I looked the code and if I understood correctly now it just set in js file, right?
As per title, the address map is not saved, only latitude and longitude
Hi,
Since this plugin isn't in w.org plugin repository, it can't be used with composer and wpackagist.org mirror. Composer repo would be awesome, and it's simple to made with packagist.
Hello there,
I am currently using your custom field inside repeatable groups but it is unable to save coordinates. Would you please help me to figure out how to fix the issue?
Cheers,
-P
CMB field map not working with CMB2 shortcode. See bug:
ReferenceError: postboxes is not defined
How to change placeholder value 'Enter a location' ?
Hi
i have not understand how install, i have read in documentation i must install like a normal plugin....but i have already cmb2, maybe i must put your folders into cmb2's folder? If yes where...
Thx
I'm sure you're busy, but thought you'd be the best person to ask for help! Hope that's okay!
I'm trying to take the CMB_Field_Map and tie it into a Gravity Forms. I've created a form where the user has the ability to drop a pin onto a map. Those map coordinates are then passed into a new post (set to draft/pending review of course). I've confirmed that Gravity forms is passing the value of the input to the appropriate entry in the DB (location_latitude & location_longitude), as the front end map tied to cmb_field_map shows the new entry immediately.
The issue I'm having is that unfortunately, in the post editor of the recently submitted map coordinates, the cmb_field_map doesn't update the pin according to the custom field location_latitude and location_longitude.
I've changed "hidden" to "text" on the lat / long inputs in cmb_field_map.php, and they too aren't being populated with the custom field location_latitude and location_longitude.
Is there any way to have those hidden fields along with the editor map check to see if the custom fields tied to them have been changed, and show the coordinates based on the location_latitude and location_longitude field, rather than simply being empty?
I'm assuming the google map would have to check the hidden (lat/long) fields and update based on those fields, and those fields would have to get the $wpdb entry for the custom fields. Unfortunately my backend tweaks are pretty limited, so any help or points in the right direction would be greatly appreciated!
Thanks again for the great plugin!
I'm missing two things on this field.
I use cmb_field_map plugin for my theme to sale. I was edit cmb_field_map (add more hidden field). Can i include it to my theme?
I have set up a new rules google cloud account because Im trying my theme on live server, I have generated API key, enqueued google-js with API key but I'm still getting in CMB2 form (Admin site) message "This page can't load Google Maps correctly" "Do you own this website?" After using Google Transition Tool result is positive and ownership is confirmed. I really don't know how to fix it. Can someone help me to sort it out?
I have tried
wp_enqueue_script('google_js','http://maps.google.com/maps/api/jskey=MY_API_KEY&sensor=false&callback=initMap')
wp_enqueue_script('google_js','//maps.googleapis.com/maps/api/jskey=MY_API_KEY&callback=initMap');
and other variations but no success. Before google new rules was all working fine If I cmd
+ click on link in enqueue_script it will run and open new window with google map loaded code.
Update: I have been on this issue spending all day. I can get maps only if I run web on terminal this mean http://192.168.1.1:8080/mywebsite and maps are running even without enqueueing google map script. Hmm. Anyway on localhost:8888/ and live server maps are not working at all. I have two different API Keys, one for live server and one for local dev. I find that maps.google.com is old call of v2 so Im using only googleapis.com .
wp_enqueue_script('google-maps', '//maps.googleapis.com/maps/api/js?key=MYAPIKEY');
If you get like this error please make sure to do the following
Enable APIs at
https://console.developers.google.com/
for
Google Maps JavaScript API
Google Places API Web Service
This is an automatic translation
Hello,
I inserted under the field of the map ('type' => 'pw_map') with a select zoom values.
How do I update the map when the value of the select?
Thank you_
Any idea why the plugin don´t load his own js, this could be the reason the map don´t load in the frontend ?
hi, is this field ready to go with CMB"?
array(
'name' => 'Location',
'desc' => 'Drag the marker to set the exact location',
'id' => $prefix . 'location',
'type' => 'pw_map',
'sanitization_cb' => 'pw_map_sanitise',
),
i use the above field declaration and the field is empty, do I need to adjust something?
The map is rendering inconsistently. (see image)
When first entering a location in the search field, the map does not render properly. However, after clicking "Save Post", the map does render properly. Then when re-opening the post for editing, the map again does not render properly.
Any guesses as to what's happening?
Note: there's currently only one other plugin activated, and it doesn't add any JS, so a conflict is improbable.
Hi, Phil.
Could it possible to add GMaps' drawing tools (https://developers.google.com/maps/documentation/javascript/examples/drawing-tools) and save these drawing coordinates?
Thanks!
This extension serves you very well in a use case, where you save a point in the map in order to show it again in the frontend.
But what about the case, when you want to output certain information about the location in the frontend (maybe even without showing a google map) - street address, city, country...
Wouldn't it be useful to add the possibility to save certain pieces of address just like you can save lat / lon separately?
It is interesting to use constant in URL, this allows me to change or custom by the theme
E.g.:
public function __construct() {
if ( ! defined( 'PW_CMB2_Field_Google_Maps_URL' ) ) {
define( 'PW_CMB2_Field_Google_Maps_URL', plugin_dir_url( __FILE__ ) );
}
add_filter( 'cmb2_render_pw_map', array( $this, 'render_pw_map' ), 10, 5 );
add_filter( 'cmb2_sanitize_pw_map', array( $this, 'sanitize_pw_map' ), 10, 4 );
}
public function setup_admin_scripts() {
wp_register_script( 'pw-google-maps-api', '//maps.googleapis.com/maps/api/js?sensor=false&libraries=places', null, null );
wp_enqueue_script( 'pw-google-maps', PW_CMB2_Field_Google_Maps_URL . 'js/script.js', array( 'pw-google-maps-api' ), self::VERSION );
wp_enqueue_style( 'pw-google-maps', PW_CMB2_Field_Google_Maps_URL . 'css/style.css', array(), self::VERSION );
}
Hi, great plugin.
Is there any way to embed this plugin inside theme folder?
In functions.php I try to add this:
require get_template_directory() . '/cmb-field-map/cmb-field-map.php';
and put the folder inside theme directory but the map doesn't work. I only saw the input field (it's not working if I type something).
Is it possible to add the plugin folder inside theme folder and call it from functions.php? Just like CMB2.
Thanks in advance
Hey,
Are you continuing to support this project, is there something I can help with?
Jordan
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.