Showing posts with label google. Show all posts
Showing posts with label google. Show all posts

Sunday, August 12, 2012

How to get Longitude / Latitude in PHP using Google Maps API

This post is just a simple script I did, built in PHP that will get the coordinates of specific location.

The script uses google maps web service that returns XML data in which we need parse to get the information we need.

Take note also of the URL I used, you just need to add your google maps key.
http://maps.google.com/maps/geo?output=xml&oe=utf-8&key=enter+your+key+here&q=enter+your+query+here

<?php

$key = 'AIzaSyCrPl5vXuNjPU1fgHF69YPxEopT_NziA4o'; // your google maps key
$param = 'T2G 0S7'; // the location you want to look for, this can be postal code, map id, address, etc.

$geoinfo = get_longlat($key, $param);
var_dump($geoinfo);

function get_longlat($key='', $param='') {
        $request_url = "http://maps.google.com/maps/geo?output=xml&key=$key&oe=utf-8&q=".urlencode($param);
        $xml = simplexml_load_file($request_url);

        $geoinfo = array();
        if (!empty($xml->Response)) {
                $point = $xml->Response->Placemark->Point;
                if (!empty($point)) {
                        $coordinates = explode(",", $point->coordinates);
                        $geoinfo = array(
                                'lon' => $coordinates[0],
                                'lat' => $coordinates[1]
                        );
                }
        }

        return $geoinfo;
}

?>

You can also get other information by parsing the XML returned by the google maps web service. Please see below for the sample XML return.

<kml>
<Response>
    <name>t2g 0s7</name>
    <Status>
        <code>200</code>
        <request>geocode</request>
    </Status>
    <Placemark id="p1">
        <address>Calgary, AB T2G 0S7, Canada</address>
        <AddressDetails Accuracy="5">
            <Country>
                <CountryNameCode>CA</CountryNameCode>
                <CountryName>Canada</CountryName>
                <AdministrativeArea>
                    <AdministrativeAreaName>AB</AdministrativeAreaName>
                    <Locality>
                        <LocalityName>Calgary</LocalityName>
                        <PostalCode>
                            <PostalCodeNumber>T2G 0S7</PostalCodeNumber>
                        </PostalCode>
                    </Locality>
                </AdministrativeArea>
            </Country>
        </AddressDetails>
        <ExtendedData>
            <LatLonBox north="51.0439997" south="51.0413017" east="-114.0367519" west="-114.0394858"/>
        </ExtendedData>
        <Point>
            <coordinates>-114.0380127,51.0426718,0</coordinates>
        </Point>
    </Placemark>
</Response>
</kml>

Monday, March 21, 2011

How to get latitude and longtitude values from google maps

There are 2 ways on how to get the latitude and longtitude coordinates from google maps.

First option is to get it using javascript:

Just follow the simple steps below to do it.

1. Go to google maps website - http://maps.google.com

2. Click to the center of the site you want.

3. Once you are at the center, copy and paste the code below on your browser's address bar.

javascript:void(prompt('',gApplication.getMap().getCenter()));

4. A pop-up message will prompt with the latitude and longtitude values enclosing with parenthesis.

5. Check the returned values by putting it to google maps search bar and enter. An arrow will point to the map where the location is.

Problem here is that you have to be at the center of the Map to get the actual coordinates.

Resource: http://lifehacker.com


Second is to get it the easier way by enabling the options on your google maps account:

Just follow the simple steps below to activate.

1. Go to google maps website - http://maps.google.com/

2. Log-in to your google account.

3. On the upper right corner of the page, you will see the Options Icon tab.

4. Click the Options Icon tab and select "Maps Labs".

5. A lightbox page will pop-up displaying all the options available for google maps.

6. Set the "LatLng Tooltip" and "LatLng Marker" to ENABLE, then save changes.

7. Go to the map, zoom in until you get to the site you want, then click and hold the "Shift" key on your keyboard.

8. You will noticed that every time you move the cursor while holding shift button, latitude and longtitude changes accordingly.


Hope you like it!! Yeah men!!

Wednesday, February 23, 2011

Exploring Google Static Maps API


The Google Static Maps API lets you embed a Google Maps image on your webpage without requiring JavaScript or any dynamic page loading. The Google Static Map service creates your map based on URL parameters sent through a standard HTTP request and returns the map as an image you can display on your web page.

The new version Static Maps API v2 will no longer requires a Maps API key which is now open and easy for everybody.

Please see my sample HTTP query string for a Static Map.

http://maps.google.com/maps/api/staticmap?center=14.559041,121.020091&zoom=14&size=300x300&maptype=roadmap&markers=color:blue|label:S|14.559048,121.020095&markers=color:green|label:G|14.559041,121.020091&markers=color:red|color:red|label:C|14.559044,121.020101&sensor=false

URL Parameters:
A Google Static Maps API URL must be of the following form:

http://maps.google.com/maps/api/staticmap?parameter1=value1&parameter2=value2...

Location Parameters:
  • center (required if markers not present) defines the center of the map, equidistant from all edges of the map. This parameter takes a location as either a comma-separated {latitude,longitude} pair (e.g. "14.559041,121.020091") or a string address (e.g. "city hall, new york, ny") identifying a unique location on the face of the earth. For more information, see Specifying Locations for more information.
  • zoom (required if markers not present) defines the zoom level of the map, which determines the magnification level of the map. This parameter takes a numerical value corresponding to the zoom level of the region desired. For more information, see Zoom Levels for more information.

Map Parameters:
  • size (required) defines the rectangular dimensions of the map image. This parameter takes a string of the form valuexvalue where horizontal pixels are denoted first while vertical pixels are denoted second. For example, 500x400 defines a map 500 pixels wide by 400 pixels high. If you create a static map that is 100 pixels wide or smaller, the "Powered by Google" logo is automatically reduced in size.
  • format (optional) defines the format of the resulting image. By default, the Static Maps API creates PNG images. There are several possible formats including GIF, JPEG and PNG types. Which format you use depends on how you intend to present the image. JPEG typically provides greater compression, while GIF and PNG provide greater detail. For more information, see Image Formats.
  • maptype (optional) defines the type of map to construct. There are several possible maptype values, including roadmap, satellite, hybrid, and terrain. For more information, see Static Maps API Maptypes for more information.
  • language (optional) defines the language to use for display of labels on map tiles. Note that this parameter is only supported for some country tiles; if the specific language requested is not supported for the tile set, then the default language for that tile set will be used.

Feature Parameters:
  • markers (optional) define one or more markers to attach to the image at specified locations. This parameter takes a single marker definition with parameters separated by the pipe character (|). Multiple markers may be placed within the same markers parameter as long as they exhibit the same style; you may add additional markers of differing styles by adding additional markers parameters. Note that if you supply markers for a map, you do not need to specify the (normally required) center and zoom parameters. For more information, see Static Map Markers for more information.
  • path (optional) defines a single path of two or more connected points to overlay on the image at specified locations. This parameter takes a string of point definitions separated by the pipe character "|". You may supply additional paths by adding additional path parameters. Note that if you supply a path for a map, you do not need to specify the (normally required) center and zoom parameters. For more information, see Static Map Paths for more information.
  • visible (optional) specifies one or more locations that should remain visible on the map, though no markers or other indicators will be displayed. Use this parameter to ensure that certain features or map locations are shown on the static map.
  • style (optional) defines a custom style to alter the presentation of a specific feature (road, park, etc.) of the map. This parameter takes feature and element arguments identifying the features to select and a set of style operations to apply to that selection. You may supply multiple styles by adding additional style parameters. For more information, see Styled Maps for more information.

Reporting Parameters:
  • sensor (required) specifies whether the application requesting the static map is using a sensor to determine the user's location. This parameter is required for all static map requests. For more information, see Denoting Sensor Usage for more information.

Resource: code.google.com

Leadership 101


  • Leadership demands sacrifices for the near-term to receive lasting benefits. the longer we wait to make sacrifices, the harder they become. Successful people make important decisions early in their life, then manage those decisions the rest of their lives.
  • Growth does not happen by chance. If you want to be sure to grow, you need a plan something strategic, specific, and scheduled. it's a discipline that would need incredible determination from us.
  • Success comes by going the extra mile, working the extra hours, and investing the extra time. The same is true for us. If we want to get to excel in any segment of life, a little extra effort can help. Our efforts can go a long way if we only work a little smarter, listen a little better, push a little harder, and persevere a little longer.
  • Making a difference in your work is not about productivity; it's about people. When you focus on others and connect with them, you can work together to accomplish great things.
  • Envision a goal you'd like to reach. Make it big enough to scare you a little. Now write down a plan for moving toward it. Create mini-goals within the big goal, to set yourself up for continual progress. And include some risks, too. Set yourself up for success.
  • Leaders build margins, not image. A leader may be forced to take unpopular stands for the good of the company. Popularity isn't bad, but decisions made solely on the basis of popular opinion can be devastating. So take courage and make the right though sometimes painful choices.