Help with Google Maps

24 posts by 9 authors in: Forums > CMS Builder
Last Post: January 20, 2010   (RSS)

Re: [Jake] Help with Google Maps

By jghoward - August 28, 2009 - edited: August 28, 2009

I'm so glad this tutorial is here. Before I get started, can you tell me if the instructions are the same if I want to show a map for just one record on a details viewer page?

UPDATE:
Awaiting your answer, but in the meantime I've made some progress.

Instead of the list code, I generated the header for the detail page.

Then, to center my map on the same point for which my record needs a marker, I used this code:

<?php foreach ($listingsRecords as $record): ?>


map.setCenter(new GLatLng(<?php echo $record['latitude'] ?>,<?php echo $record['longitude'] ?>), 13);
var point = new GLatLng(<?php echo $record['latitude'] ?>,<?php echo $record['longitude'] ?>);
var marker = createMarker(point,'<?php echo htmlspecialchars($record['street_address'], ENT_QUOTES) ?>, <?php echo htmlspecialchars($record['city'], ENT_QUOTES) ?>')
map.addOverlay(marker);

<?php endforeach; ?>

}

Okay, so my map is working when I load record number from end of url i.e. map.php?address-field-1
Can you tell me how to call the iframe from listingsDetail.php in a way that dynamically loads the correct map.

Will this approach work? Is there a better way?
Why do I need the iframe? Can't I just load the map on the same listingsDetail.php?address-field-1 page?

Re: [jghoward] Help with Google Maps

By Chris - September 3, 2009 - edited: September 3, 2009

Hi jghoward,


Okay, so my map is working when I load record number from end of url i.e. map.php?address-field-1
Can you tell me how to call the iframe from listingsDetail.php in a way that dynamically loads the correct map.


You'll want to do something like this, but change $listingsRecord to the name of the record variable if it's different:

<iframe src="/path/to/map.php?<?php echo $listingsRecord['num'] ?>" width="550" height="350"></iframe>


Will this approach work? Is there a better way?
Why do I need the iframe? Can't I just load the map on the same listingsDetail.php?address-field-1 page?


Yes, it will work. There's really nothing wrong with this approach.

More recent versions of the Google Map API do away with the <iframe> in favour of a <div>. If you're interested in that, I've attached a sample listing page (for multiple records) which uses the V3 API! :D

I hope this helps! Please let us know if you have any questions or comments.
All the best,
Chris
Attachments:

listingsmap.php 3K

Re: [chris] Help with Google Maps

By Codee - January 20, 2010

here's another site that makes it easy to get the longitude and latitude for locations:
http://stevemorse.org/jcal/latlon.php