PHP Google Maps Tutorial

Google Maps is one of the most popular Internet mapping services. Google's mapping programming interface can be used for Web page development in a variety of languages. PHP is a server-side scripting language used by Web developers to create dynamically generated content along with the Google Maps API. You must register for a developer key to access the API from your website.

Instructions

    • 1

      Open your Integrated Development Environment by double-clicking on the desktop program icon or under the "Program Files" sub-menu of the "Start" menu.

    • 2

      Open a new PHP file by selecting the appropriate file menu option on your IDE and enter the following variables that will be used to store position data in the PHP Web page:

      $myLongitude = "";
      $myLatitude = "";
      $myPrecision = "";

    • 3

      Define the query string variables for accessing the Google Maps API, including your Google Maps API Key, the city and state of the target location, and an output type and location for the information looked up through the Google Maps API. To use the code for a significant amount of data, change the output type from comma separated values (csv) to XML:

      $myKey = "YOUR Google Maps API Key";
      $myAddress = urlencode("lexington KY");
      $myUrl =
      "http://maps.google.com/maps/geo?q=".$myAddress."&output=csv&key
      =".$myKey;

    • 4

      Define a CURL request, to prevent information headers from being returned, and complete other basic setup information for the Google Maps API call with the following PHP code:

      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL, $myUrl);
      curl_setopt($ch, CURLOPT_HEADER,0);
      curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]);
      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

      $myData = curl_exec($ch);
      curl_close($ch);

    • 5

      Display the latitude and longitude of the city and state entered for the "myAddress" variable in the previous step:

      $myData = explode(",",$data);
      $myPrecision = $data[1];
      $myLatitude = $data[2];
      $myLongitude = $data[3];
      echo "Latutide: ".$myLatitude."<br>";
      echo "Longitude: ".$myLongitude."<br>";

    • 6

      Save and view the PHP generated webpage.

Related Searches:

References

Resources

Comments

You May Also Like

  • Google Maps Mashup Tutorial

    Every business is looking for customers, and customers are looking for businesses and other destinations whose locations they do not know. Google...

  • How to Retrieve a Google Maps API Key

    Google Maps is a robust online mapping service provided by Google featuring satellite imagery, street view navigation and an easy-to-use interface. Google...

  • Google Maps Tutorial

    Reliable directions can be difficult to come by. Google, however, has made getting directions a lot simpler with its Google Maps. All...

  • Help to Get Rid of a Google Maps API Key Pop-Up

    If you notice a pop-up message relating to a Google Maps application program interface (API) key on your website, you need to...

  • How to Save a PHP File & Attach it to Your Web Page

    PHP is a Web programming language developed to permit website developers to create interactive Web pages. PHP is generally embedded inside a...

  • Google Street View Tutorial

    Google offers a powerful mapping tool that you can use to locate businesses, get directions or find interesting places around the globe....

  • How to Register a Google Maps Key

    Google Maps is a free, Web-based mapping service developed by Google. In addition to providing traditional street mapping and route planning functionality,...

  • Google Page Creator Tutorial

    Internet users can create simple free webpages for personal, professional or business use. A user may wish to upload a webpage to...

  • How to Use Google Maps in C#

    C# is an interpretive programming language developed by the Microsoft Corporation for use in the .NET development environment. By creating a C#...

  • How to Use XML Google Maps

    When developing a website, the need for many different features and tools will arise. One of these may be a map program....

  • How to Save a Google Map

    Google tries to continue to improve its products. It has made it easy for a user to save maps in its My...

  • How to Use Flex Builder & Google Maps

    Flex Builder is developed by Adobe to support productivity applications such as Google Maps, which also has an application programming interface (API)...

  • How to Create Google Maps Application

    Google Maps is the epitome of Web 2.0. Unlike its predecessors, Google Maps provides an application programming interface (API) that allows programmers...

  • How to Copy a File From a URL with PHP

    PHP (which stands recursively for "PHP Hypertext Processor") is a powerful scripting language. It is used most commonly to develop interactive web...

  • How to Use Google's Training Tutorial and Free Online Classes

    Google offers a variety of tutorials and classes you may take or teach for free at their Google Code University. Because Google...

  • Troubleshooting Problems With Google Maps

    Google Maps is a web-mapping application that allows you to view maps, as well as get driving directions for many destinations. It...

  • How to Install Google Maps

    When you are out and need to find out where an address is or how to get there, the Google Maps application...

  • How to Insert a Decimal in PHP MySQL

    PHP provides many standard functions for handling MySQL databases. This means that inserting data into a MySQL database table using a PHP...

  • How to Use Google Maps on Your Website

    The Google Maps application programming interface makes it easier than ever to create searchable interactive maps for embedding in websites, email and...

  • How to Use Google Maps to Map Data

    Google Maps is a popular and free online mapping service that provides traditional maps, driving directions, location photos and satellite imagery. Within...

Related Ads

Featured