Using Mule to get Geo Code for address

For last few days i am playing around with Mule, its really cool integration framework. You can use it to build integration applications by using small amount of code. I had this requirement where given address i wanted to get the Geo Coding information for that address, I wanted to use Google Maps API for getting GeoCode information for the address. The way Google Maps API works is it has a REST API, it takes address as query string and it returns JSON structure. Ex. If you copy paste this URL in the browser Oak Road,Walnut Creek,CA,94597&sensor=false You will get a JSON structure with longitude and latitude embedded in lot of other information

   "results" : [
         "address_components" : [
               "long_name" : "3055",
               "short_name" : "3055",
               "types" : [ "street_number" ]
               "long_name" : "Oak Road",
               "short_name" : "Oak Rd",
               "types" : [ "route" ]
               "long_name" : "Walnut Creek",
               "short_name" : "Walnut Creek",
               "types" : [ "locality", "political" ]
               "long_name" : "Contra Costa County",
               "short_name" : "Contra Costa County",
               "types" : [ "administrative_area_level_2", "political" ]
               "long_name" : "California",
               "short_name" : "CA",
               "types" : [ "administrative_area_level_1", "political" ]
               "long_name" : "United States",
               "short_name" : "US",
               "types" : [ "country", "political" ]
               "long_name" : "94597",
               "short_name" : "94597",
               "types" : [ "postal_code" ]
         "formatted_address" : "3055 Oak Road, Walnut Creek, CA 94597, USA",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 37.9302338,
                  "lng" : -122.0582288
               "southwest" : {
                  "lat" : 37.9302299,
                  "lng" : -122.0582466
            "location" : {
               "lat" : 37.9302299,
               "lng" : -122.0582466
            "location_type" : "RANGE_INTERPOLATED",
            "viewport" : {
               "northeast" : {
                  "lat" : 37.93158083029149,
                  "lng" : -122.0568887197085
               "southwest" : {
                  "lat" : 37.9288828697085,
                  "lng" : -122.0595866802915
         "types" : [ "street_address" ]
   "status" : "OK"
Out of all the data returned by Google MAPS api i am only interested in the Lat and Long and i want to return it in GeoJSON format like this

Which is [lng,lat] format, some open source JavaScript Mapping frameworks understand the GeoJSON format. I built a simple Mule integration application which takes STREETLINE1, CITY, STATE, ZIPCODE as argument and returns geo location in GeoJSON format like this [lng,lat]. I followed these steps to build the application
  1. First i built a Mule Flow which looks like this
    In this flow i have a composite input source that could take input on either VM transport or HTTP transport and then uses the values submitted by user to make a request to Google Maps API. Once the response is returned it uses DataMapper to convert the big response that Google Maps API returns into simple GeoJSON response.
  2. This is how the Data Mapping file looks like
    If you look at the script of this file it looks like this
After deploying this application i can make the POST call to http://localhost:9081/geocode URL and see the location in geojson format like this


Anonymous said...

Thank you. Your blog was very helpful and efficient For Me,Thanks for Sharing the information Regards mulesoft training in hyderabad

Louis Martin said...

Nice Post about geocoding.

Geocoding API

Samatha Ravula said...

I am really enjoying reading your well-written articles. It looks like you spend a lot of effort and time on your blog. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work...

Mulesoft online course

Unknown said...

the blog is good and Interactive it is about mulesoft it is useful for students and Mulesoft Developers for more updates on Mulesoft

Morgan said...

Hello There,

Thank you! Thank you! Thank you! Your blog was a total game changer!

Mock is a feature provided by MUnit to mock the behavior of the message processor. Basically, MUnit replaces the actual behavior of message processor with the behavior defined by the user.
There are various scenarios where we can use the Mock Message processor. Imagine we have completed the development of a Mule application and need to test it,

Appreciate your effort for making such useful blogs and helping the community.

Kevin Lee said...

Hi There,

Allow me to show my gratitude bloggers. You guys are like unicorns. Never seen but always spreading magic. Your content is yummy.So satisfied.

Previously, I wrote a blog post about IT Engineering here at MuleSoft and how we use MuleSoft products at MuleSoft. Inter-team communication is critical for us to complete projects and we decided to implement a Centre for Enablement (C4E) approach internally. The MuleSoft customer success team offered evolved approach to developing MuleSoft applications for IT.
Excellent tutorials - very easy to understand with all the details. I hope you will continue to provide more such tutorials.

Kind Regards,

Ganesh Ponna said...


Allow me to show my gratitude bloggers. You guys are like unicorns. Never seen but always spreading magic. Your content is yummy. So satisfied.

What is the difference between web APIs and web services? Let’s start off with an analogy: all tigers are cats but not all cats are tigers. In a similar way, all web services are APIs, but not all APIs are web services. Web APIs and web services are often confused with each other; however, web APIs are an evolution of web services. Both facilitate information transfer, but web APIs are more dynamic than web services are.

Thanks a lot. This was a perfect step-by-step guide. Don’t think it could have been done better.

Kind Regards,

Morgan lee said...

Hello Buddy,

Love it absolutely! So crystalline. No mumbo jumbo. No non-sense. Straight and simple. You guys need a standing ovation for your good work.
I started using Mulesoft Training USA blog for my training practice.
Recently, the RAML team decided it was time for an updated server infrastructure. The original site used a web-based Content Management System (CMS) that required a lot of costly server resources. Each client request to the CMS invoked scripts that rendered the pages from outside sources, such as the database and theme;
This led to significant processing time before providing what was, in most cases, a static page. Of course, we ran a caching layer in front of the web server to speed up some requests,

It was cool to see your article pop up in my google search for the process yesterday. Great Guide.
Keep up the good work!

Thanks a heaps,
Morgan lee

akhila priya said...

This concept is a good way to enhance the knowledge.thanks for sharing. please keep it up salesforce Online Training Bangalore

srjwebsolutions said...

We are leading responsive website designing and development company in Noida.
We are offering mobile friendly responsive website designing, website development, e-commerce website, seo service and sem services in Noida.

Responsive Website Designing Company in Noida
Website Designing Company in Noida
SEO Services in Noida
SMO Services in Noida

Vikas Chaudhary said...

Battery Mantra is Authorized exide car battery dealer in Noida and Greater Noida. We are providing our service in Indirapuram, Delhi, Ashok Nagar.

Exide Battery Dealer in Noida
Battery Dealer in Noida
Authorized Battery Dealer in Noida
Car Battery Dealer in Noida
Car Battery Dealer
Exide Battery Dealer

EG MEDI said... is online medical store pharmacy in laxmi nagar Delhi. You can Order prescription/OTC medicines online. Cash on Delivery available. Free Home Delivery

Online Pharmacy in Delhi
Buy Online medicine in Delhi
Online Pharmacy in laxmi nagar
Buy Online medicine in laxmi nagar
Onine Medical Store in Delhi
Online Medical store in laxmi nagar
Online medicine store in delhi
online medicine store in laxmi nagar
Purchase Medicine Online
Online Pharmacy India
Online Medical Store