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
Thanks for any help,
Zick
Re: [zick] Geocode on multi viewer
By Jason - February 21, 2011
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
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
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
By Toledoh - February 22, 2011
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
Tim (toledoh.com.au)
Re: [Jason] Geocode on multi viewer
By Codee - May 28, 2011
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: [equinox69] Geocode on multi viewer
By Jason - May 30, 2011
You can create a new .php page that only displays your map. Once you have that working the way you want to, you can include that page as an iframe in your main page.
Hope that 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 Codee - May 30, 2011