Thursday, July 11, 2013

Google Map on a Field

We have seen lots of code for google map implementation. But, all codes are for Visualforce pages. Users created a visualforce page and classes for implement google map. But,

Today I introduce you how you implementation of  google map on a Field.

For This, you will need to create a Custom Label with these values -
Name :               GApiKey
Short Description : GApiKey
Value  :                      BbiTjwR8z1eBST0mNpJvtWvmgvEdrgGXs5szHHahQdD86Zd50nyAzG0QAkxwmgieQrLQ


Then create a Formula field ( type - text) with this formula value - 

IMAGE(
"http://maps.google.com/maps/api/staticmap?center=" + BillingStreet + "," + BillingCity + "," + BillingState + " " + BillingPostalCode +"&zoom=13&size=650x250&markers=color:blue|" + BillingStreet + "," + BillingCity + "," + BillingState + " " + BillingPostalCode + "&sensor=false&format=png32&key=" + $Label.GApiKey
, "no map available", 250, 650)

After adding this field in a object page payout, Result will shows like -


I created a Location name formula field for demo to show Google Map on Field. 
Here the link for online demo:

11 comments:

  1. Hi,
    Is this all you have to do? I successfully created the new Label, then try to create a Custom Field under the Account object (I tried Contacts too), copying and pasting your formula into the field. I receive this syntax error:
    Error: Field BillingStreet may not be used in this type of formula

    Any thoughts on what's going on here?

    ReplyDelete
    Replies
    1. Please can you share you code and screen shot. Because we was applied this Its works fine. Please share you code.

      Delete
  2. I did as you said but I got the no map available message. Strange. It looks great if I could get it to work. Very neat.

    ReplyDelete
  3. Hello Aidy,

    Have You created a Custom label or not with the same value?
    If yes, please can you share your code. I will try to figure out the problem.

    Thanks

    ReplyDelete
  4. @aidy @ Raj Jha don't you need your own GApiKey for this to work? Also, try https: instead?

    ReplyDelete
  5. @Raj n Andrew,

    Even after using my own GApi Key n using Https, Still not able to get the maps
    Could you help me to know why is this so.?

    ReplyDelete
  6. Hi All,
    I know lots of persons are facing same problem. But guys this formula work for me.
    Please can you all do little bit of change. Remove the API key from formula. Because all are facing problem in API. I have tried this formula after remove the API and its still working. Please guys replace with new formula -

    IMAGE(

    "http://maps.google.com/maps/api/staticmap?center=" + BillingStreet + "," + BillingCity + "," + BillingState + " " + BillingPostalCode +"&zoom=13&size=650x250&markers=color:blue|" + BillingStreet + "," + BillingCity + "," + BillingState + " " + BillingPostalCode + "&sensor=false&format=png32" , "no map available", 250, 650)


    Thanks,
    -Raj

    ReplyDelete
  7. Thanks alot for sharing it. It worked with your updated formula

    ReplyDelete
  8. what code would i have to change to see the streetview?

    ReplyDelete
  9. @jharaj This isnt working out for me. I get a "no map available" error.

    Any suggestions?

    Thanks,
    Rithu

    ReplyDelete
    Replies
    1. hi! Can You please help me out I am also getting the same error even after using the last formula it's still showing no map available.

      Delete