API Examples

Beer Mapping API Code Examples:

This page will be displaying multiple examples of ways to interact with the Beer Mapping API. Currently we are only displaying php5 functions using simplexml.

If you would like to submit code examples, please feel free to contact us about it. If we post them here, we will also display a link to your application.


A php5 Locquery Example:

This example is performing a location query for the term "Goose Island" We have tried to keep example as simple and readable as possible so we have separated html tags onto their own lines away from the content.

	<?php
	$name_query = 'goose+island';
	//using simplexml we will load the proper url for a location query (substitute your api key of course)
	$xml = simplexml_load_file('http://beermapping.com/webservice/locquery/API_KEY/'.$name_query);
	//we will loop through any possible returned values.
	foreach($xml->location as $location){
		//if we want to use the unique id: $location->id;
		
		//first we print the location name and link to the review page
		echo '<p><a href="'.$location->reviewlink.'">';
		echo $location->name;
		echo '</a>';
		echo '<br />';
		//next we echo address:
		echo  $location->street;
		echo '<br />';
		echo $location->city.', '. $location->state.' '.$location->zip;
		echo '<br />';
		echo $location->country;
		echo '<br />';
		echo $location->phone;
		echo '</p>';
	}
	?>
	

A php5 Locimage Example:

This example is performing a location image query for the id "1530". We know that this is the id for the Map Room in Chicago because we did a locquery for it earlier. We have tried to keep example as simple and readable as possible so we have separated html tags onto their own lines away from the content.

	<?php
	$image_query = '1530';
	//using simplexml we will load the proper url for a location image query (substitute your api key of course)
	$xml = simplexml_load_file('http://beermapping.com/webservice/locimage/API_KEY/'.$image_query);
	//we will loop through any possible returned values.
	foreach($xml->location as $location){
		echo '<p>';
		echo '<a href="';
		echo $location->directurl;
		echo ' alt="'.$location->caption.'" title="'.$location->caption.'"';
		echo '">';
		echo '<img src="';
		echo $location->thumburl;
		echo '" alt="" title="" />';
		echo '</a>';
		echo '<br />';
		echo $location->caption;
		echo '<br />';
		echo '<a href="';
		echo $location->crediturl;
		echo '" alt="credit for this image" title="credit for this image">';
		echo $location->credit;
		echo '</a>';
		echo '</p>';
	}
	?>