Google Maps -Fabrik 1.6

Status
Not open for further replies.

sevens

New Member
Hi all,
I have 2 fields that contain latitude and longitude, so the thread http://fabrikar.com/forums/showthread.php?t=4819 doesn't really help because it explains how to get the lat lon in a form. I'm trying to link to a google map by using the lat and lon fields that are already populated in a table view. Any help would be greatly appreciated. The answer probably lies within the forum I mentioned above but as a noob to PHP, not sure how to extract code. Thanks!
 
try making this as a table template:

Code:
<?php

//change these variables:

//this is the full element name which contains the lat/lon data
$latlonfield = 'jos_fabrik_formdata_15___latlon';

//this is your google maps key
$key = 'ABQIAAAAyRaoxDvoKkGViNtAL4gOyxT2yXp_ZAY8_ufC3CFXhHIE1NvwkxSri_0kPK2d7SOF1V93FNVog39mwg';


//the width of you map
$w = 500;

//the height of your map
$h = 500;
?>

<div style="width:<?php echo $w ?>px;height:<?php echo $h ?>px" id="map">

</div>

<script type="text/javascript"  src="http://maps.google.com/maps?file=api&v=2&key=<?php echo $key ?>" ></script>
<script type="text/javascript">
window.addEvent('domready', function(){
  if (GBrowserIsCompatible()) {
  console.log('compat');
    var map = new GMap2($("map"));
    map.addControl(new GSmallMapControl());
    map.addControl(new GMapTypeControl());
    <?php
    foreach ($this->rows as $gkey => $group) {
        foreach ($group as $row) {
            $coords = explode(",", $row->$latlonfield);
            if(count($coords) < 2){
                continue;
            }
            ?>
var point = new GLatLng(<?php echo $coords[0]?>, <?php echo $coords[1]?>);
 map.setCenter(point, 13);
var marker = new GMarker(point);
    GEvent.addListener(marker, "click", function() {
      marker.openInfoWindowHtml("<b>GPS Coords</b><br />Lat: " + <?php echo $coords[0]?> + "<br />Long: " + <?php echo $coords[1]?>);
    });
    map.addOverlay(marker);
            <?php
        }
    }
?>
}
})
</script>

hth
Rob
 
I have 2 separate fields: latitude and longitude. So, the below wouldn't work, correct?

Code:
//change these variables:

//this is the full element name which contains the lat/lon data
$latlonfield = 'jos_fabrik_formdata_15___latlon';
 
correct ;)

try

Code:
<?php

//change these variables:

//this is the full element name which contains the lat/lon data
$latfield = 'jos_fabrik_formdata_15___lat';
$lonfield = 'jos_fabrik_formdata_15___lon';

//this is your google maps key
$key = 'ABQIAAAAyRaoxDvoKkGViNtAL4gOyxT2yXp_ZAY8_ufC3CFXhHIE1NvwkxSri_0kPK2d7SOF1V93FNVog39mwg';


//the width of you map
$w = 500;

//the height of your map
$h = 500;
?>

<div style="width:<?php echo $w ?>px;height:<?php echo $h ?>px" id="map">

</div>

<script type="text/javascript"  src="http://maps.google.com/maps?file=api&v=2&key=<?php echo $key ?>" ></script>
<script type="text/javascript">
window.addEvent('domready', function(){
  if (GBrowserIsCompatible()) {
    var map = new GMap2($("map"));
    map.addControl(new GSmallMapControl());
    map.addControl(new GMapTypeControl());
    <?php
    foreach ($this->rows as $gkey => $group) {
        foreach ($group as $row) {
            $lat = $row->$latfield;
            $lon = $row->$lonfield;

            ?>
var point = new GLatLng(<?php echo $lat?>, <?php echo  $lon?>);
 map.setCenter(point, 13);
var marker = new GMarker(point);
    GEvent.addListener(marker, "click", function() {
      marker.openInfoWindowHtml("<b>GPS Coords</b><br />Lat: " + <?php echo $lat?> + "<br />Long: " + <?php echo  $lon?>);
    });
    map.addOverlay(marker);
            <?php
        }
    }
?>
}
})
</script>
 
I'm a little confused by your first post. When you say you are "trying to link to a Google map by using the lat and lon fields that are already populated in a table view". Do you actually want to display the map in place in the table, or simply point a link at Google to display the map?

-- hugh
 
so you have your table with its lan and lon fields in right?

So next you need to make a table template for it to display the data on the map, details of how to do that are in this FAQ:

http://fabrikar.com/forums/showthread.php?t=6151

you need to replace all of the content in template.php with the code posted above. (Watch out I just saw I left an error in so have edited and updated the post)

hth
Rob
 
I created the table view but I don't think I was clear. I've attached a sample of my table headers that includes latitude and longitude. To display map, I was hoping to have another element that is only visible when an item is clicked to view more details. The element "get directions" would link to the Google map.
 

Attachments

  • Picture 9.png
    Picture 9.png
    7.5 KB · Views: 221
In which case, the example I created in the thread you referenced in your first post pretty much does everything you need. It'll need slight modification to use separate lat/long elements, but that's about it.

As I explain in that thread, when the form is viewed in 'read only' mode (i.e. from the default View link on your table) it will display the map automatically.

So ... lets move this discussion over to that thread, and I can help you through the changes you'll need for you specific requirements. For instance, you won't need to geoCoding from an address, as you already have the lat/lon.

If you'd like to post a followup on that other thread, and pretty much re-post your last post from this thread, I'll respond there.

-- hugh
 
lol ok well I completely misunderstood what you wanted. Hugh is right the other thread is a better place to continue this discussion

Cheers
Rob
 
No problem! I don't think I was very clear when I asked for help. I've moved to other thread so hopefully Hugh can assist. Thanks!
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top