Google Base

5 posts by 2 authors in: Forums > CMS Builder
Last Post: January 18, 2010   (RSS)

By richc - January 18, 2010

Has anyone used Google Base to submit real estate feeds to Google Maps?

See http://maps.google.com.au/help/maps/realestate/data_provider_faq.html

Basically need to create an XML file and either have it updated daily or triggered to update when a new listing is added.

Thanks!

Re: [richc] Google Base

By Chris - January 18, 2010

Hi richc,

While I haven't used this service before, I can help get you started.

Firstly, you'll want to find a sample of the XML you'll want to generate. I found one here: http://base.google.com/base/intl/en_au/rss-v2.xml

I took that code and threw a foreach around one of the <item> tags, (removing the other <item> tags,) then pasted in a STEP 1 from using the CMSB Code Generator to make a listings page. After replacing some of the example content from the original <item> tags with code to output fields from CMSB, I ended up with this:

<?php header('Content-type: application/xml; charset=utf-8'); ?>
<?php

require_once "C:/wamp/www/CMSB-TRUNK/cmsAdmin/lib/viewer_functions.php";

list($listingsRecords, $listingsMetaData) = getRecords(array(
'tableName' => 'listings',
));

?>
<rss version ="2.0" xmlns:g="http://base.google.com/ns/1.0">
<channel>
<title>Sample RSS v2.0 AU Real Estate feed</title>
<description>A description of your content.</description>
<link>http://www.realestateautest.example.com</link>

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

<item>
<title><?php echo htmlspecialchars($record['title']) ?></title>
<g:bathrooms><?php echo htmlspecialchars($record['bathrooms']) ?></g:bathrooms>
<g:bedrooms><?php echo htmlspecialchars($record['bedrooms']) ?></g:bedrooms>

<g:item_type>Housing</g:item_type>
<description><?php echo htmlspecialchars($record['content']) ?></description>
<link rel="alternate" type="text/html" href="<?php echo htmlspecialchars($record['_link']) ?>"/>
<g:price><?php echo htmlspecialchars($record['price']) ?></g:price>
<g:price_type>negotiable</g:price_type>
<g:property_type>house</g:property_type>

<g:listing_type>residential for sale</g:listing_type>
</item>

<?php endforeach ?>

</channel>
</rss>


Note that you'll need to change the filepath to viewer_functions.php (in red above, you can find yours at the top of any viewer page you've generated.) You'll likely also need to change the field names (also in red above) to match your own section.

The above feed only includes the "Required" fields. Once you have that working, you can start adding the "Recommended" and "Optional" fields listed at http://base.google.com/support/bin/answer.py?answer=66779&hl=en_AU .

I hope this helps! Please let me know if you have any questions.
All the best,
Chris

Re: [richc] Google Base

By Chris - January 18, 2010

Hi richc,

You can use PHP to generate an XML file. If your Content-type is correct (set by the first line in the sample above) and the XML is well-formed, the only difference between a static XML file and your PHP file (from the XML consumer's perspective) will be the URL (e.g. http://example.com/example.xml vs. http://example.com/example.xml.php). XML consumers tend not to be concerned with what URLs look like, instead focusing on Content-type headers. People do this all the time, serving dynamically-generated XML files from PHP.

If you want to test this out, get an example.xml file working, then rename it example.xml.php, prepend the <?php header('Content-type...') ?> line above, and make sure that works.

If this actually does turn out to be a problem (which I doubt), you might be able to trick your web server into serving your PHP script from a URL which mimics a static XML file (e.g. http://example.com/example.xml). Only after you've exhasted these approaches would I recommend publishing a separate, static XML file, as this would require either a cron job or human intervention to keep updated, as well as requiring some custom programming to write.

I hope this helps. Please let me know if you have any questions.
All the best,
Chris

Re: [chris] Google Base

By richc - January 18, 2010

Thanks for the quick response Chris!

I'm already using that method ( eg rss.xml.php) successfully for rss feeds and google map input ... my site is www.hawkes-bay.co.nz

Strangely though Google base seems to specify that an xml extension must be used - see http://base.google.com/support/bin/answer.py?answer=59542&hl=en_GB

However I will try to register a .php datafeed and see what happens...