How to save google map image to server

Once I was assigned a task to make a functionality that saves the google map images to the server. I searched on the internet but was unable to find any existing solution. But then an idea comes to my evil genius mind and I implemented it. Now I am sharing the logic with you all. Here is the code:

  $gmap = new SplFileObject('google_map.png','w');
  $image = file_get_contents(",CA&zoom=14&size=400x400&sensor=false");

How It works:

The Google static map API provides a way to get the image by providing the parameters through query strings and google process these parameters and returns an image in png format by default. I called a PHP function file_get_contents to retrieve the image data in variable and wrote it in new image file named “google_map.png”.

That is so simple :)

Note: Google allows its maps for the web browsers only, so displaying google map image to any other thing such as PDF and printing purpose may need special license from Google. For information please read License restrictions at

Tags: , ,

Sunday, October 17th, 2010 PHP

10 Comments to How to save google map image to server

  • Sundas Akbar says:

    thanks faisal bhai :-) i searched alot to do for this type of explanation but unable to find :-(

    very very thanks

  • Abdul Jamal says:

    oh yeah very help full jani for those who need this…………bcx once my client need the same scenario………….i searched a lot but not got any useful way to implement :-)
    same scene i made…………

    Abdul Jamal

    Software Engineer(PHP)

  • Faisal says:

    That is my pleasure. Please feel free to request any article that you are unable to search. I will be happy to help you all. Thanks for such appreciation.

  • Abdul Jamal says:

    jani as im starting zend framework can you please help me to configure it im very thankful to you :-) ;-p

  • Abdul Jamal says:

    Thanks jani :-)

    Abdul Jamal

    Software Engineer(PHP)

  • Naveed Malik says:

    Dear Faisal Bhae,

    Yaar thanks a lot, I have searched the GOOGLE for two days but all said no solution.
    LOVELY you are ….. you were also suggested by by Google (b.t.w) :)

  • Michael says:

    Have you published the next part of “A comprehensive guide: How to install Zend Famework” configuring the example. I can’t seem to get the virtualhost to work.

  • Leave a Reply to Sundas Akbar