Google map on header with all my companies
Author | Posts |
---|---|
April 18, 2013 at 2:06 pm 2464 | |
noomia | Hi guys ! I'm trying to create something similar to this theme right now : http://preview.ait-themes.com/directory/wp1/ I have a custom post type wich is called "companies". The company creation is allowed on the front end and have a google map field. What I want is show a google map on the header of my site wich show all the companies thanks to the address users entered on the company front end form. Thanks a lot :) ! |
April 18, 2013 at 2:37 pm 2467 | |
Tareq Hasan | You can use a shortcode: `[wpuf-meta name=”meta_key_name” type=”map”]` or the function `wpuf_shortcode_map( ‘meta_key’, $post->ID );` |
April 18, 2013 at 3:01 pm 2472 | |
noomia | In fact, I need 1 maps, with all the companies … Is it doing the trick :s ? |
April 18, 2013 at 3:09 pm 2475 | |
noomia | Ok I have figured it out… But I need to get only the lat value and the lng value of the google map field… How could I do that ? |
April 18, 2013 at 3:15 pm 2477 | |
Tareq Hasan | Sorry, I thought you just needed the map for one post. In that case, you need to get all posts and fetch the custom field. Lat and long are saved in the same custom field, separated by a comma. Using `explode( ‘,’, $value )` will give you array of lat and long. |
April 18, 2013 at 3:37 pm 2480 | |
noomia | Thanks Tareq, With a mix of this post and what you told me, I was able to achieve my goal 🙂 ! Thanks ! |
April 18, 2013 at 8:33 pm 2485 | |
Mahi | Hello @noomia, If possible please share your solution with us 🙂 ? Cheers. |
April 19, 2013 at 8:09 am 2523 | |
noomia | Hi ! So, according to this post and what Tareq told me, here is what I did : First of all, put the following html code where you want to have your Google Map (I choose the header.php file) : ` Then, you need to create a .js file that will initialize the google maps. Let’s call it maps.js : ` var latlng = new google.maps.LatLng(48.856667, 2.350833); var map = new google.maps.Map(document.getElementById(“map_canvas”), myOptions); var bounds = new google.maps.LatLngBounds(); function addMarker(location, map, bounds) { $(function() { })(jQuery); ` which will contains the Google Map. Now, this is the important part. In your function.php file, put these lines of code : add_action(‘wp_enqueue_scripts’, ‘companies_map_scripts’); function companies_map_scripts() { wp_register_script( ‘maps’, get_bloginfo(‘stylesheet_directory’) . “/js/maps.js”, array(‘jquery’, ‘googlemaps’), false, false ); $locations = array(); $location_query = new WP_Query( array( while ( $location_query->have_posts() ) { $address = get_post_meta( get_the_ID(), ‘address’, true ); $locations[] = array( wp_reset_postdata(); wp_localize_script(‘maps’, ‘php_args’, array( You have to change : – `XXXXXXXXXXXX` : change it with your Google API Key. Finally, add these lines to your style.css : |