How To Use FMTC’s Local Deal Feed

We may earn money or products from the companies mentioned in this post.

fmtc local deal feed
FMTC provides a local deal feed, aggregating deals from Groupon, Living Social and more. But with over 20,000 local deals, you can’t just dump them on a page. So how could you use this data?

First, let’s look at the data structure of a local deal (XML shown, but JSON also available)

<item>
 <couponid>int</couponid>
 <merchantid>int</merchantid>
 <mastermerchantid>int</mastermerchantid>
 <merchantname>string</merchantname>
 <network>string</network>
 <label>string</label>
 <restrictions>string</restrictions>
 <couponcode>string</couponcode>
 <affilateurl>string</affilateurl>
 <directurl>string</directurl>
 <skimlinksurl>string</skimlinksurl>
 <startdate>YYYY-MM-DDTHH:MM:SS-UTC</startdate>
 <enddate>YYYY-MM-DDTHH:MM:SS-UTC</enddate>
 <image>string</image>
 <dealtypes>
  <type>string</type>
 </dealtypes>
 <categories>
  <category>string</category>
 </categories>
 <status>status</status>
 <lastupdated>YYYY-MM-DDTHH:MM:SS-UTC</lastupdated>
 <price>string</price>
 <listprice>string</listprice>
 <discount>string</discount>
 <percent>string</percent>
 <threshold>string</threshold>
 <local>
  <businessname>string</businessname>
  <businessurl>string</businessurl>
  <fineprint>string</fineprint>
  <html>string</html>
  <locations>
   <location>
    <address>string</address>
    <address2>string</address2>
    <city>string</city>
    <state>string</state>
    <postalcode>string</postalcode>
    <phone>string</phone>
    <country>string</country>
    <region>string</region>
    <latitude>string</latitude>
    <longitude>string</longitude>
   </location>
  </locations>

  <options>
   <option>
    <optionid>int</optionid>
    <description>string</description>
    <saleprice>float</saleprice>
    <wasprice>float</wasprice>
    <discount>float</discount>
    <percent>int</percent>
   </option>
  </options>

 </local>
</item>

Most of the item is like any other deal, but local deals include a <local> property, containing information about the physical location of the business.

Local Deals Based on Zip Code and Type

What if you loaded our local deals into your database, then pulled out Dentist offers within 25 miles of a zip code?

First, look at the name of the company or the deal label for dentist, dentistry, dental, etc. Then, calculate the distance from the location of the deal (location latitude & longitude) versus your center point.

What's Here? in Google MapsHow do you find the latitude & longitude of my center point? Go to Google Maps, browse to your center point, right-click and choose “What’s Here?”. Google Maps will tell you the latitude & longitude of the spot you clicked.

How do you find the distance between two points? Thanks to the Earth not being flat, this can be quite complicated. Lucky for you, Stack Overflow exists. This should get you started:

SELECT *, ( 3959 * acos( cos( radians(42.966869) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(-78.864849) ) + sin( radians(42.966869) ) * sin( radians( latitude ) ) ) ) AS distance FROM local_deals HAVING distance < 25 ORDER BY distance

3959 is a constant to measure the distance in miles; make this 6371 to measure in km.

Plot Local Deals on Map

You can go a step further and take those results and plot them on a map using the Google Maps API.

Allow User Input

Instead of pre-selecting the map location, you can let your users choose where to focus in the results. But most people don't know their latitude and longitude. Luckily, they do know their zip code, so grab a free zip code / latitude longitude database and lookup the latitude and longitude from their zip code.

Geotarget the User

Finally, you know more about your users than you think, including (roughly) where they're at. By using a free geoip database, you can get the approximate latitude / longitude of the user ($_SERVER['REMOTE_ADDR'] in PHP).

Put It All Together

  1. Download and save FMTC's Local Deals to MySQL
  2. Download and save the Zip Code to Latitude / Longitude data to MySQL
  3. Download and save the GeoIP data to MySQL
  4. Query the GeoIP data from the user's IP to get their approximate latitude and longitude, then query MySQL for deals close to them. Display in a list and on a map
  5. Allow the user to enter another zip code to find deals in other locations

Finally, if you wanted to get fancy, you could use mod_rewrite in apache and build out thousands of pages of local deals based on category and zip code (ex: domain.com/zipcode/category).

What are you waiting for? Sign up for a free trial of FMTC

Follow and like FMTC: