PHP Map + Location Plugin

PHP Map + Location Plugin


This is a collection of location based functions that can get a users location based on their ip address using the IPInfoDB api, return advanced details on a specific location with the Yahoo PlaceFinder api, or dynamically create maps (as images or with javascript) using the Google Maps api.

IP Location

This function interacts with the API to get a users location based on their IP address. It can return city, state, country, latitude & longitude and is accurate within a 25 mile radius. This function accepts an IP Address and returns an array of location based values.

$location = $location->ip ($_SERVER['REMOTE_ADDR']);

// Values returned
Your IP Based Location

Country: United States
Country Code: US
State: Washington
City: Kirkland
Post Code:
Latitude: 47.6966
Longitude: -122.197

On the map

PHP Map + Location Plugin - 1

See below on how to generate maps

Place Finder

This function uses the Yahoo PlaceFinder API to get detailed information about a specific location. This is the way to go if you want to get more detailed information or find a more exact location. It accepts a textual location (zip code, city/state, street address, latitude/longitude, etc) and returns an array of location based values.

$info = $location->info ('400 Broad St Seattle, WA 98109');

// Values returned

Country: United States
Country Code: US
State: Washington
State Code: WA
County: King County
City: Seattle
Post Code: 98109
Cross Street: Near the intersection of Broad St and John St
House: 400
Street: Broad St
Radius: 500
Quality: 87
Where on Earth ID: 12798953
Latitude: 47.619859
Longitude: -122.348749

Google Maps

Use this to automatically generate Google Maps for a specific location. This function accepts a number of parameters:

  • 1. location (required. options: latitude and longitude)
  • 2. format (options: javascript, jpg, jpg-baseline, png, png32, gif))
  • 3. map type (options: roadmap, hybrid, satellite, terrain)
  • 4. width (options: value in px or %)
  • 5. height (options: value in px or %)
  • 6. zoom level (options: number between 1 and 21)
  • 7. id (options: any valid css id)

Example 1 (Javascript)

The first example uses javascript to generate a dynamic map. To generate a map with javascript you’ll need to pass both the latitude and longitude coordinates to the location parameter (the latidude and longitude can be retreived with either the ip location or place finder functions descriped above). The map is injected into a div with an id of “map_canvas” by default (whose height/width can be modified via css). If you want to set the width & height with css instead of via the function, pass “css” to both the width and height parameters.

$coordinates = $info['latitude'].','.$info['longitude'];
echo $location->map($coordinates, 'javascript', 'hybrid', '100%', '300px', '16', 'map_1');

PHP Map + Location Plugin - 2

Google Maps (Image)

Currently the map function in only able to add one javascript map per page. If you need multiple maps (or just want to generate an image instead) simply set the second parameter to the type of image you want returned (jpg, jpg-baseline, png, png32 or gif). You can set the dimensions to anything you like, but Google’s maximum allowed image size is 630 by 630 pixels. A few examples of different image settings follow…

echo $location->map($coordinates, 'png32', 'roadmap', '630px', '630px', '11', 'map_2');

PHP Map + Location Plugin - 3

echo $location->map($coordinates, 'jpg', 'satellite', '630px', '200px', '7', 'map_3');

PHP Map + Location Plugin - 4

echo $location->map($coordinates, 'gif', 'terrain', '200px', '200px', '5', 'map_4');

PHP Map + Location Plugin - 5

echo $location->map($coordinates, 'png', 'satellite', '630px', '200px', '1', 'map_5');

PHP Map + Location Plugin - 6

More Files From the PHP Plugin Suite


Image Plugin

Twitter Plugin

Video Plugin

Weather Plugin

pose css


Author Image