I'm building a site that integrates Drupal 7 with Google Maps API V3 to provide users with GPS data and narrative descriptions of all the non-motorized outdoor recreational trails in my area. Currently the website uses the Views module to provide a listing, with some summary data of the trails. When you click on a specific trail its node detail page is opened showing a Google Map of that trail with a KML file overlaid to show all the respective trail information. I accomplished this writing a simple module that gathers the latitude, longitude, and kml url from the node object and then sends it to my Google Maps JavaScript file by using the drupal_add_js module as follows.
$node = menu_get_object();
$latitude = $node->field_latitude['und'][0]['value'];
$longitude = $node->field_longitude['und'][0]['value'];
$filename = $node->field_file['und'][0]['filename'];
$mapURL = "http://goaroostookoutdoors.com/sites/default/files/trails/kml/" . $filename;
$settings = array(
'Latitude' => $latitude,
'Longitude' => $longitude,
'mapURL' => $mapURL,
);
drupal_add_js(array('map_settings' => $settings), 'setting');
The final thing I need to accomplish before making this site live is to provide an overview map that would be positioned above the Views listing of all the trails. The map would be integrated with the view so that the sort/filter functionality in the right hand sidebar would affect both the map, and the listing of trails below. For example, if a user wants only Mountain Biking trails that are Easy they would select the appropriate checkboxes on the right sidebar, hit apply, and then my Google Map would update to show only Mountain Biking Icons, and the views listing below would only show mountain biking trails that are easy.
Does anyone know how I could pull the longitude, latitude, and possibly activity of each trail that views is listing and then send them to my Google Maps API similar to how I did it on the trail detail page.
Any help would be so hugely appreciated!
Comments
Any help here?
I read through the Views 3 API documentation and am still at a loss. Has anyone tackled this or something similar and have a few thoughts to share?
_
I'm not exactly sure I understand what you're asking, but you can get the result of a view by using
views_get_view_result( 'VIEW_MACHINE_NAME', $display_id, $arg1, $arg2);. You can then examine that array for the values you need to pass on in the settings array.Nice solution WF. I didn't
Nice solution WF. I didn't know how to get the data from views, but I've done a lot of google maps integration. That's exactly how you would do it. Turn all the results into an array, and pass it to the javascript with drupal_add_js(). From there you can use javascript and the google maps API to define the map.
Contact me to contract me for D7 -> D10/11 migrations.
_
yeah-- i remember feeling like I'd struck gold when i stumbled across that views function, lol.
WorldFallz, thank you for
WorldFallz, thank you for pointing me towards something, I'll dig in further and see how it works. Sounds like it could be very promising! Thanks again.
I need to know how to program better!
Many thanks for your help so far!
With the views_get_page_view() I've been able to pull out the information I need for a single result by using the following code:
Now instead of printing only result[0] I'd like to iterate up through the whole results using a foreach loop and print the longitude/latitude for every result. What's the easiest way to do this, for whatever reason (probably because I'm in over my head) I can't figure it out.
Thanks so much in advance!
<?php$locations =
Contact me to contract me for D7 -> D10/11 migrations.