Geocode on multi viewer

8 posts by 4 authors in: Forums > CMS Builder: Plugins & Add-ons
Last Post: May 30, 2011   (RSS)

By Mikey - February 21, 2011 - edited: February 21, 2011

Is it possible to get the geocode add-on to work on a multi viewer page. Example: I need to create a multi listing page of property listings and each property will need it's very own map display on the listing page, next to the property description. The multi page will displays 5 properties per page, where the site visitor would then click next to see the following 5 properties - each with it's very own map.

Thanks for any help,
Zick

Re: [zick] Geocode on multi viewer

By Jason - February 21, 2011

Hi Zick,

Yes, this is possible, but if you're producing one separate map using javascript for each record, it can start to get really slow. A quick work around that would be quicker would be to use an iframe for each record that embeds a google map. You can do this with the latitude and longitude fields created by the plugin. Here's an example of what it would look like:

<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?ll=<?php echo $record['latitude'];?>,<?php echo $record['longitude'];?>;output=embed"></iframe><br />

Hope this helps get you started.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Geocode on multi viewer

By Mikey - February 21, 2011

Hey Jason,
I plugged in the code you provided, but it's returning a generic Google map search page inside the iframe. Do you know if I need to apply for a google API key to get this working?

As an alternative, could you explain what I'd need to do if I where to use the javascript to generate the maps.

Here's the code I'm using:

///////////////////////////////////// geo records /////////////////////////////////////
list($myRecords, $myMetaData) = getRecords(array(
'tableName' => 'properties',
//'tableName' => $GLOBALS['GEOCODER_SAMPLE_TABLENAME'],
//'where' => whereRecordNumberInUrl(1),
//'limit' => '1',
));
$record = @$myRecords[0]; // get first record
///////////////////////////////////// end geo records /////////////////////////////////////

// load records
list($propertiesRecords, $propertiesMetaData) = getRecords(array(
'tableName' => 'properties',
'perPage' => '3',
//'allowSearch' => false,
));

$propertiesRecord = @$propertiesRecords[0]; // get first record



<!-- geomap -->
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
function initialize() {
var latitude = <?php echo floatval(@$record['latitude']); ?>;
var longitude = <?php echo floatval(@$record['longitude']); ?>;
var mapCanvasId = 'map_canvas';
if (latitude) {
var mapOptions = { mapTypeId: google.maps.MapTypeId.ROADMAP };
var map = new google.maps.Map(document.getElementById(mapCanvasId), mapOptions);
var latLng = new google.maps.LatLng(latitude, longitude);
var marker = new google.maps.Marker({map: map, position: latLng });

map.setCenter(latLng);
map.setZoom(14);
}
}
</script>
<!-- /geomap -->




<!-- geomap -->
<?php if (@$record['latitude']): ?>
<br />
<div id="map_canvas" style="width: 400px; height: 240px; float: left; margin: 0px 0px; border: 1px solid #CCC;"></div>
<?php endif ?>

<?php if (!@$record['latitude']): ?>
<?php ?>
<?php endif ?>

<!-- /geomap -->

Re: [zick] Geocode on multi viewer

By Jason - February 22, 2011

Hi Zick,

You shouldn't need an API key. Could you show me a url where you tried this so I can take a look?

To use the javascript from the example code, you'd need to put the javascript that produces a single map in a foreach loop that would output that block of code for each record you returned.

You'd also need to make sure that you where giving each map a unique id.

Hope this helps get you started.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [zick] Geocode on multi viewer

Hey Zick.

Not sure if this helps (my brain's going a bit slow today) but have a look at http://www.ragatzdeanconsulting.com/index2.php

This is using a jQuery plugin, and the Geo plugin and works a treat. More about that here http://www.interactivetools.com/iforum/gforum.cgi?post=84402
Cheers,

Tim (toledoh.com.au)

Re: [Jason] Geocode on multi viewer

By Codee - May 28, 2011

Hi Jason,
I am using the geocoder on a page that will have other javascript that interrupts the geocoder-generated google map code:
<!-- STEP3: Map with single address: Put this where you want your map displayed, rename $record if needed -->


<?php if (@$record['latitude']): ?>
<div id="map_canvas" style="width: 299px; height: 299px; float: left; margin: 0px 15px;"></div>
<?php endif ?>

<?php if (!@$record['latitude']): ?>
<div style="width: 299px; height: 299px; float: left; margin: 0px 15px; border: 1px solid #000;">
<div style="text-align: center; padding-top: 135px">
No map available!
</div>
</div>
<?php endif ?>
<!-- STEP3: /Map with single address -->


How would I embed this in an iframe? The string you provided in this thread generates a generic google map of the west coast of the US.
Thanks!

Re: [Jason] Geocode on multi viewer

By Codee - May 30, 2011

That makes sense!...and I DO have it working on the separate page. Have a great holiday!