Stefan's posterous

Stefan's posterous

Stefan  //  

Jun 15 / 1:01am

Infochimps Data Marketplace / Commons: Download Sell or Share Databases, statistics, data sets for free

Search for data   9,744 datasets and counting!

Post your data

Sell your data or share it for free, forever.

Post your data

Request data

Looking for hard-to-find data?

Request data



Infochimps is the place to find data online. We have data of any size, shape or format. You can sell data at a price and license you set, or share open data for free. We're the best source for bulk social network data such as Twitter and MySpace. We have tons of big data.


Try our bookmarklet!

Drag this link: Infochimp! to your bookmarks folder, and click it when you spot a ripe data banana.

You'll have to be a registered user to use it, so please take a second and sign on up while you're here.

Learn more about how you can help Catalog the World's Structured Data


Jun 11 / 3:13pm

Externalized PHP Strings Performance for Internationalization - SQLITE Anyone? - Jim Plush's Programming Paradise

Externalized PHP Strings Performance for Internationalization - SQLITE Anyone?

October 26, 2005

I just got started down the road of interationalizing our core enterprise product and I have to admit, I'm scared shitless. :)
After getting training for 4 days on everything you must take into account its staggering how much work needs to be done to internationalize a product. Things that need to be taken into consideration:

  • Table Column length - if your tables are formatted for english only you're going to have a problem when german comes around and needs to expand by 40%. Is your app ready to have all the text in the gui expanded by at least 40%?

  • Text in images - A no no if you want to have localization turned around in a reasonable amount of time. Imaging redoing all your graphics in every language you want to support? yikes. So replace those text in images with just text and maybe a nice background image.

  • String Matching - You cannot do anything with strings anymore :) no more strstr, str_replace, preg_match's without unicode character support. How do you know what strings will be coming in? String length? Some japanese characters have 3 bytes in a character, strlen will just return the number 3 however its only one character. For this you'll need MBSTRING extension since PHP does not support multibyte chars natively (PHP6 will in the next couple of YEARS).

  • Inline CSS/Hardcoded Markup - have bold tags all over? lose em. Bold in Japanese does nothing but leave the text unreadable, Have small fonts? You'll need to at least support 10pt fonts and 13pt line height to allow for japanese/chinese height expansion. You can externalize your bold tags using a span with a css class called bold <span class="bold"> Also all fonts must be externalized to a localizable CSS file because ARIAL or VERDANA fonts do not support japanese or chinese characters

  • Unfair claims - in Germany for example its illegal to claim a product is "the best" or "the fastest" IE "My script is the fastest PHP script of its kind"

  • Externalize those strings! - No hardcoded strings can be found in your HTML or PHP code, they must be replaced from a strings file that can be sent out to a translator.

  • Security Questions - not everyone has a favorite basketball team, or social security #, or a favorite football team so think about common things in all countries if you're going to ask someone a question to remember their password

  • But they're just pictures! - The seemingly innocent thumbs-up gesture is offensive in Australia, a picture of your hand making a "hitchhiking" sign will get your ass kicked in Nigeria, showing your hand like a stop sign is offensive in greece on the same scale as giving someone the finger.

  • Concatination - root of all evil. A Simple String like
1
  1. echo getString("welcome") . ', '.$user;

which would echo out "Welcome, JimmyP" would be offensive in Japanese (Japanese readers expect the subject of this sentence to be at the start, not the end as well as not have -san at the end) and there is no way to externalize that so the proper way would be to do something like
1
  1. $string = getString("welcomeUser");
  2. $value = str_replace("%USERNAME%", $user, $string);
  3. echo getString("welcomeUser");

where your string would be "Welcome, %USERNAME%" which can be sent to a translator and understood that this is a welcome message with a user name Variable.


So what is the best way to externalize your strings? I did some initial performance testing and this is what I've come up with so far:

1. INI FILE - store all your strings in a .ini file such as welcomeMsg = "Hi There" which can be parsed with parse_ini_file()

2. Native PHP Arrays - store your strings in a .php file using $msg['welcomeMsg'] = "Hi There"; which can be just included as a native php array

3. XML Format - store your strings as <string code="welcomeMsg">Hi There</string> and parsed using php5's simpleXML

4. SQL LITE - storing your strings in a SQL lite DB per language and having a function wrapper for queries

the winner???
well in a test of 50,000, 10,000 and 1,000 string files #4 SQL LITE was FIVE times as fast as SimpleXML (2nd place) and something like 20 Times faster than parsing INI files.

here are the #'s

== Testing Methods ==

Testing was done adding additional text on every 4th iteration to add more realistic string data contents such as 400 character strings every 4th element to mimic filesize and parsing time.

=== Native PHP Arrays ===
This test was done using a file containing php's native arrays
<BR>
Example: $msg['key'] = "value";
<pre>

1
  1. &lt;?PHP
  2. $msg['keyname0'] = "valueofstring0testinglongerstringsinthisfileforgoodiegoodielengthtestinglongerstringsinthisfileforgoodiegoodielengthtestinglongerstringsinthisfileforgoodiegoodielengthtestinglongerstringsinthisfileforgoodiegoodielength";
  3. $msg['keyname1'] = "valueofstring1";
  4. $msg['keyname2'] = "valueofstring2";
  5. $msg['keyname3'] = "valueofstring3";
  6. ?&gt;

50,000 strings

.69
.68
.64
.59
.64
.60

10,000 strings

.23
.23
.23
.21
.22

=== XML File Format ===
Tested using an xml file that is parsed with php5's simplexml's methods for accessing strings

<BR>
Example: <string key="key">value</value>

1
  1. &lt;?xml version="1.0" encoding="UTF-8" ?&gt;
  2. - &lt;strings&gt;
  3. &lt;string key="key0"&gt;valueofstring0testinglongerstringsinthisfileforgoodiegoodielengthtestinglongerstringsinthisfileforgoodiegoodielengthtestinglongerstringsinthisfileforgoodiegoodielengthtestinglongerstringsinthisfileforgoodiegoodielength&lt;/string&gt;
  4. &lt;string key="key1"&gt;valueofstring1&lt;/string&gt;
  5. &lt;string key="key2"&gt;valueofstring2&lt;/string&gt;
  6. &lt;string key="key3"&gt;valueofstring3&lt;/string&gt;
  7. &lt;string&gt;
  8. &lt;/strings&gt;

<BR>
50,000 strings

.32 sec
.34 sec
.37 sec
.41 sec
.38 sec

10,000 strings

.14 sec
.15 sec
.15 sec
.07 sec
.15 sec

1,000 strings

.01 sec
.01 sec
.01 sec
.01 sec
.01 sec

=== INI FILE TYPE ===
Parsing .ini files using the parse_ini_file method in PHP
[php]
key0 ="valueofstring0testinglongerstringsinthisfileforgoodiegoodielengthtestinglongerstringsinthisfileforgoodiegoodielengthtestinglongerstringsinthisfileforgoodiegoodielengthtestinglongerstringsinthisfileforgoodiegoodielength"
key1 ="valueofstring1"
key2 ="valueofstring2"
key3 ="valueofstring3"
[/php

50,000 strings

.68
.65
.63
.60
.65

10,000 strings

.21
.22
.22
.18
.21

1,000 strings

.02
.02
.02
.02
.02

SQL LITE--------------
Got a little tip from Wez Furlong about SQLITE in PHP5 and boy was he right, using SQLITE on 50,000 strings, picking out the strings you needed took a teeeeeny tiny .07 seconds!

This post was posted on October 26, 2005 in the following sections: PHP. There are currently 27 comments.

-->

Comments

RSS feed for comments on this post.

The URI to TrackBack this entry is: http://www.litfuel.net/plush/bblog/trackback.php/84/-->
  1. timvw says:
    November 3, 2005 @ 00:31 — Reply

    Have you had a look at http://www.php.net/gettext?

  2. Jim says:
    November 4, 2005 @ 01:06 — Reply

    yep, but we dismissed it after a few trials. It wasn't working for our needs so we needed a custom solution to work with our translation teams overseas.

  3. Max Barel says:
    July 23, 2006 @ 15:40 — Reply

    If this thread is still alive, can you elaborate on why gettext did't fill your needs? I plan to use it and don't want to miss the point.

  4. Amit Gupta says:
    November 6, 2005 @ 10:23 — Reply

    how about MySQL for storing Unicode characters? MySQL does support unicode chars using the unicode collation as well as several language specific collations!! PS:- which syntax hiliting plugin are you using? its broken in several places, if you just take a look, you'll know!!

  5. Elliot Anderson says:
    November 13, 2005 @ 08:08 — Reply

    "The seemingly innocent thumbs-up gesture is offensive in Australia" ... Im an Aussie and I have never heard that before.

  6. Shawn says:
    November 22, 2005 @ 08:33 — Reply

    great article. may just have to implement this in one of my big projects. '"The seemingly innocent thumbs-up gesture is offensive in Australia" ... Im an Aussie and I have never heard that before.' .. Ditto

  7. Jim says:
    November 22, 2005 @ 19:38 — Reply

    really you guys haven't heard of that one? maybe they got the country wrong then.

  8. Anonymous says:
    February 13, 2006 @ 15:22 — Reply

    There are some custom scripts you may use for UTF-8 encoding. See http://cms.naczasie.pl/lgpl/UTF-8.php, find DOWNLOAD and click :)

  9. Bruce Sauls says:
    May 28, 2010 @ 21:17 — Reply

    Comment pending moderation

  10. Ben says:
    April 14, 2006 @ 23:55 — Reply

    Hi, informative article, thanks. Just thought I'd point out what appears to be a mistake, for the benefit of future googlers. In your second code example, you have 'echo getString("welcomeUser");' but I think you mean 'echo $value;'.

  11. Mgccl says:
    June 19, 2007 @ 23:13 — Reply

    Just how can you access those strings in XML? I mean, once you convert the XML file into simpleXML objects, what would you do to find the key and return the string?

  12. speps says:
    July 1, 2007 @ 15:49 — Reply

    @Mgccl : see the PHP documentation for SimpleXMLElement->xpath() and maybe you will need to find doc about XPath too (google or wikipedia).

  13. Web developers says:
    August 21, 2009 @ 16:49 — Reply

    Humm... interesting, If this thread is still alive, can you elaborate on why gettext did't fill your needs? I plan to use it and don't want to miss the point. Thanks

  14. blu ray ripper says:
    April 18, 2010 @ 10:53 — Reply

    Comment pending moderation

  15. Hollywood Wallpapers says:
    April 19, 2010 @ 01:32 — Reply

    Comment pending moderation

  16. Aditya Yadav says:
    May 12, 2010 @ 06:14 — Reply

    Comment pending moderation

  17. 642-062 says:
    May 19, 2010 @ 07:52 — Reply

    Comment pending moderation

  18. shopping says:
    May 21, 2010 @ 12:17 — Reply

    Comment pending moderation

  19. HID lights says:
    May 23, 2010 @ 10:25 — Reply

    Comment pending moderation

  20. fat burning furnace scam says:
    June 1, 2010 @ 16:34 — Reply

    Comment pending moderation

  21. virbram five fingers says:
    June 5, 2010 @ 03:14 — Reply

    Comment pending moderation

  22. coach outlet says:
    June 7, 2010 @ 08:53 — Reply

    Comment pending moderation

  23. Billig Stromlieferant says:
    June 7, 2010 @ 12:27 — Reply

    Comment pending moderation

  24. links of london says:
    June 8, 2010 @ 01:36 — Reply

    Comment pending moderation

  25. MKV to iPad says:
    June 9, 2010 @ 07:50 — Reply

    Comment pending moderation

  26. LOuIs VuItToN Damier Graphite Canvas says:
    June 10, 2010 @ 05:16 — Reply

    Comment pending moderation

  27. Jany Robert says:
    June 11, 2010 @ 10:35 — Reply

    Comment pending moderation

Leave a Comment

Line and paragraph breaks automatic, HTML allowed: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <code> <em> <i> <strike> <strong>

May 28 / 3:00pm

Comparing E-mail Address Validating Regular Expressions

/^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@([a-z0-9]([-a-z0-9_]?[a-z0-9])*(\.[-a-z0-9_]+)*\.(aero|arpa|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|travel|mobi|[a-z]{2})|([1]?\d{1,2}|2[0-4]{1}\d{1}|25[0-5]{1})(\.([1]?\d{1,2}|2[0-4]{1}\d{1}|25[0-5]{1})){3})(:[0-9]{1,5})?$/i

http://blog.tuxz.net/archives/2009/03/27/email_validation_using_regular_expression/
Uses preg_match()
These should be valid
l3tt3rsAndNumb3rs@domain.com valid
has-dash@domain.com valid
hasApostrophe.o'leary@domain.org valid
uncommonTLD@domain.museum valid
uncommonTLD@domain.travel valid
uncommonTLD@domain.mobi valid
countryCodeTLD@domain.uk valid
countryCodeTLD@domain.rw valid
lettersInDomain@911.com valid
underscore_inLocal@domain.net valid
IPInsteadOfDomain@127.0.0.1 valid
IPAndPort@127.0.0.1:25 valid
subdomain@sub.domain.com valid
local@dash-inDomain.com valid
dot.inLocal@foo.com valid
a@singleLetterLocal.org valid
singleLetterDomain@x.org valid
&*=?^+{}'~@validCharsInLocal.net valid
foor@bar.newTLD invalid
 
These should be invalid
missingDomain@.com invalid
@missingLocal.org invalid
missingatSign.net invalid
missingDot@com invalid
two@@signs.com invalid
colonButNoPort@127.0.0.1: invalid
invalid
someone-else@127.0.0.1.26 invalid
.localStartsWithDot@domain.com invalid
localEndsWithDot.@domain.com invalid
two..consecutiveDots@domain.com invalid
domainStartsWithDash@-domain.com invalid
domainEndsWithDash@domain-.com invalid
numbersInTLD@domain.c0m invalid
missingTLD@domain. invalid
! "#$%(),/;<>[]`|@invalidCharsInLocal.org invalid
invalidCharsInDomain@! "#$%(),/;<>_[]`|.org invalid
local@SecondLevelDomainNamesAreInvalidIfTheyAreLongerThan64Charactersss.org valid

Valid: 18/19
Invalid: 17/18

May 26 / 1:20am

The Google Places API (Developer Preview) - Google Maps API Web Services - Google Code

The Google Places API (Developer Preview)

The Google Places API will launch in July, 2010. Please consult this preview documentation for details on how the service works. To use this API, you must satisfy our Acceptable Use Requirements.

Note: To use the Google Places API you must first request a Maps API client ID and cryptographic key which you must use to sign your request URLs. For information on signing URL requests, please see the URL Authentication documentation within the Web Service APIs home page.

Introduction

The Google Places API is a service that returns information about a "place" (hereafter referred to as a Place) — defined within this API as an establishment, a geographic location, or prominent point of interest — using an HTTP request. Place requests specify locations as latitude/longitude coordinates.

Two basic Place requests are available: a Place Search request and a Place Details request. Generally, a Place Search request is used to return candidate matches, while a Place Details request returns more specific information about a Place.

This service is designed for processing place requests generated by a user for placement of application content on a map; this service is not designed to respond to batch of offline queries, which are a violation of its terms of use.

Audience

This document is intended for website and mobile developers who want to add local business and point of interest information within maps provided by one of the Google Maps APIs. It provides an introduction to using the API and reference material on the available parameters.

Acceptable Use Requirements

To obtain access to this API, users must agree to the following acceptable use guidelines and fill out an official application form:

  • Applications using the service must comply with the Google Maps API Terms of Service.
  • All developers wishing to use the service must already have an Adsense account, or must create one prior to applying.
  • Applications that wish to use the API must only issue queries in response to end user actions.
  • The results of every search made by applications using this API must be shown to a user.
  • Place Details requests must only be made in response to user interaction with place Search results, or to refresh the details of a previously requested Place. It is not permitted for an application to iterate over all Search results to obtain details for every result.
  • Applications may not reorder or manipulate Search results.
  • Applications must display any branding or sponsorship of search results returned by the API.
  • Applications may not store any Place data permanently except References and IDs.
  • If screen size constraints prevent a map being shown with search or details results the Powered by Google logo must be shown.
  • Place information collected using this API, or any data derived from it, such as Place location corrections, can not be distributed in any way, such as through an API, without the express permission of Google.

The Places API will launch in July, 2010. The documentation contained here is a developer preview. Developers wishing to use the Place API should fill out a Places API Application Form.

A more complete and detailed set of requirements will be documented closer to launch, and these listed requirements (and the documentation) may change in future. Notifications of such changes will be sent to the relevant Google Group.

Usage Limits

Query limits for the Google Places API will be set closer to launch and may be specific to each application depending on the use case and traffic estimates

Note: the Places API may only be used in conjunction with displaying results on a Google map; using Place data without displaying a map for which Place data was requested is prohibited. Additionally, calculation of Place information may generate copyrights, warnings and/or advertising which must be displayed to the user in some fashion.

Place Searches

The Places API has two types of requests, which are related: Place Search requests and Place Details requests. A Place Search request initiates a request for "places" around a provided location, often provided via geolocation (so that a user can search for the Place they are currently located or Places nearby). The Places API returns a list of candidate places that are near the provided location and the user can then initiate a Place Details request on a specific entity returned in the original search.

Place Search Request

A Place Search request is an HTTP URL of the following form:

1 http://maps.google.com/maps/api/place/search/output?parameters

where output may be either of the following values:

  • json (recommended) indicates output in JavaScript Object Notation (JSON)
  • xml indicates output as XML

Certain parameters are required to initiate a Place Search request. As is standard in URLs, all parameters are separated using the ampersand (&) character. The list of parameters and their possible values are enumerated below.

  • location (required) — The textual latitude/longitude value from which you wish to retrieve place information.
  • radius (required) — The distance (in meters) within which to return Place results.
  • sensor (required) — Indicates whether or not the Place request came from a device using a location sensor (e.g. a GPS) to determine the location sent in this request. This value must be either true or false.
  • client (required) — Specifies the registered application using this service.
  • signature (required) — The generated value of signing this URL using the client's cryptographic key. (See URL Authentication for more information.)

Place Search Responses

Place Search responses are returned in the format indicated by the output flag within the URL request's path.

Place Search JSON Output

A sample JSON Place Search request is shown below, asking for places for about a mile around Williamsburg, Brooklyn:

1 http://maps.google.com/maps/api/place/search/json?location=40.717859,-73.957790&radius=1600&client=clientId&sensor=true_or_false&signature=SIGNATURE

The JSON response is shown below. (Note that Places API reference elements have been shortened for clarity. Additionally, the full array of results has been shortened.

1 {  "status": "OK",  "results": [ {    "name": "Williamsburg",    "types": [ "locality", "political" ],    "icon": "http://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png",    "reference": "ClRBAAAAXP...lHAPyHom2aG"  }, {    "name": "Greenpoint",    "vicinity": "New York",    "types": [ "neighborhood", "political" ],    "icon": "http://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png",    "reference": "CkQ_AAAAhd...MF45fwr44Ek"  }, {    "name": "Peter Luger Steakhouse",    "vicinity": "Broadway, Brooklyn",    "types": [ "restaurant", "food", "establishment" ],    "icon": "http://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png",    "reference": "ClRCAAAAt3...6Nt7k11iQdT"  }, {    "name": "Music Hall of Williamsburg",    "vicinity": "North 6th Street, Brooklyn",    "types": [ "establishment" ],    "icon": "http://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png",    "reference": "ClRFAAAAN...6UOKCbjv7Sxy"  },  ...additional results ...    ],  "html_attributions": [ ]}

The JSON response contains three root elements:

  • "status" contains metadata on the request. See Status Codes below.
  • "results" contains an array of places, with information about the place. See Place Search Results for information about these results. The Places API returns up to 20 establishment results. Additionally, political results may be returned which serve to identify the area of the request.
  • html_attributions contain a set of attributions about this listing which must be displayed to the user.

Of particular interest within the results are the reference elements, which can be used to request more specific details about the establishment via a separate query. These references are temporary and expire after 15 minutes. (See Place Details Requests below.)

Note that these results generally need to be parsed if you wish to extract values from the results. Parsing JSON is relatively easy. See Parsing JSON for some recommended design patterns.

Place Search XML Output

You may optionally request XML results within a Place Search request using the /xml output flag. A sample XML request is shown below, performing an identical Place Search request as shown in the JSON example above:

1 http://maps.google.com/maps/api/place/search/xml?location=40.717859,-73.9577937&radius=1600&client=clientId&sensor=true_or_false&signature=SIGNATURE

The XML returned by this request is shown below.

1 <PlaceSearchResponse>  <status>OK</status>  <result>   <name>Williamsburg</name>   <type>locality</type>   <type>political</type>   <icon>http://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png</icon>   <reference>CkRAAAAAUhZG...Yy0b4-sd1zCUu9P8</reference>  </result>  <result>   <name>Greenpoint</name>   <vicinity>New York</vicinity>   <type>neighborhood</type>   <type>political</type>   <icon>http://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png</icon>   <reference>CkQ-AAAAHIDo...nYmSR8l52FmkMH6c</reference>   <name>Peter Luger Steakhouse</name>   <vicinity>Broadway, Brooklyn</vicinity>   <type>restaurant</type>   <type>food</type>   <type>establishment</type>   <icon>http://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png</icon>   <reference>ClRBAAAATIpR...mHSxoyiRcr_FVuww</reference>  </result>   ...additional results...</PlaceSearchResponse>  

Note that the XML response consists of a single <PlaceSearchResponse> and two top-level elements:

  • <status> contains metadata on the request. See Status Codes below.
  • Zero of more <result> elements, each containing information about a single establishment. See Place Search Results for information about these results. The Places API returns up to 20 establishment results. Additionally, political <type> results, or streets, may be returned which serve to identify the area of the request.
  • html_attributions contain a set of attributions about this listing which must be displayed to the user.

We recommend that you use json as the preferred output flag unless your application requires xml for some reason. Processing XML trees requires some care, so that you reference proper nodes and elements. See Parsing XML with XPath for some recommended design patterns for output processing.

The remainder of this documentation will use JSON syntax. In most cases, the output format does not matter for purposes of illustrating concepts or field names in the documentation. However, note the following subtle differences:

  • XML results are wrapped in a root <PlaceSearchResponse> element.
  • JSON denotes entries with multiple elements by plural arrays (results), while XML denotes these using multiple singular elements (<result>).
  • Blank elements are indicated through empty arrays in JSON, but by the absence of any such element in XML. A response that generates no results will return an empty results array in JSON, but no <result> elements in XML, for example.

Status Codes

The "status" field within the Place Search response object contains the status of the request, and may contain debugging information to help you track down why the Place Search request failed. The "status" field may contain the following values:

  • "OK" indicates that no errors occurred; the place was successfully detected and at least one result was returned.
  • "ZERO_RESULTS" indicates that the search was successful but returned no results. This may occur if the search was passed a latlng in a remote location.
  • "OVER_QUERY_LIMIT" indicates that you are over your quota.
  • "REQUEST_DENIED" indicates that your request was denied, generally because of lack of a sensor parameter.
  • "INVALID_REQUEST" generally indicates that the query parameter (location or radius) is missing.

Place Search Results

When the Places service returns results from a search, it places them within a (JSON) results array. Even if the service returns no results (such as if the location is remote) it still returns an empty results array. (XML responses consist of zero or more <result> elements.)

Each element of the results array contains a single result from the specified location and within the specified radius, ordered by prominence. The result may also contain attribution information which must be displayed to the user.

Each result within the results field may contain the following fields:

  • name contains the human-readable name for the returned result. For establishment results, this is usually the business name.
  • vicinity contains a feature name of a nearby location. Often this feature refers to a street or neighborhood within the given results. This vicinity can be used to further refine results or disambiguate similar results.
  • types[] contains an array of feature types describing the given result.
  • icon contains the URL of a recommended icon which may be displayed to the user when indicating this result.
  • reference contains a unique time-sensitive token that you can use to retrieve additional information about this place in a Place Details request. Currently, this token is valid for 15 minutes from the original search request.

Place Details

Once you have a reference from a Place Search request, you can request more details about a particular establishment or point of interest by initiating a Place Details request. A Place Details request returns more comprehensive information about the indicated place such as its complete address, phone number, user rating, etc.

Place Details requests should be made in response to the selection of a search result by a user. You may not use a Place Details request to request details for all results returned by a search before they are presented to the user.

Place Details Requests

A Place Details request is an HTTP URL of the following form:

1 http://maps.google.com/maps/api/place/details/output?parameters

where output may be either of the following values:

  • json (recommended) indicates output in JavaScript Object Notation (JSON)
  • xml indicates output as XML

Certain parameters are required to initiate a search request. As is standard in URLs, all parameters are separated using the ampersand (&) character. The list of parameters and their possible values are enumerated below.

  • reference (required) — The textual identifier uniquely identifying a place. Thus reference ID will either be a temporary value returned from a Place search request or a permanent value stored from a previous Place Details request.

Place Details Responses

Place Details responses are returned in the format indicated by the output flag within the URL request's path.

Place Details JSON Output

A sample JSON request is shown below, calculating Place Details requests for a particular establishment:

1 http://maps.google.com/maps/api/place/details/json?reference=REFERENCE_ID&client=clientId&sensor=true_or_false&signature=SIGNATURE

The JSON response is shown below. (Note that the Places API reference ID has been shortened for clarity.

1 {  "status": "OK",  "result": {    "name": "Peter Luger Steakhouse",    "vicinity": "Broadway, Brooklyn",    "types": [ "restaurant", "food", "establishment" ],    "formatted_phone_number": "(718) 387-7400",    "formatted_address": "178 Broadway, Brooklyn, New York 11211, United States",    "address_components": [ {      "long_name": "178",      "short_name": "178",      "types": [ "street_number" ]    }, {      "long_name": "Broadway",      "short_name": "Broadway",      "types": [ "route" ]    }, {      "long_name": "Brooklyn",      "short_name": "Brooklyn",      "types": [ "locality", "political" ]    }, {      "long_name": "Kings",      "short_name": "Kings",      "types": [ "administrative_area_level_2", "political" ]    }, {      "long_name": "New York",      "short_name": "New York",      "types": [ "administrative_area_level_1", "political" ]    }, {      "long_name": "11211",      "short_name": "11211",      "types": [ "postal_code" ]    } ],    "geometry": {      "location": {        "lat": 40.7099090,        "lng": -73.9625800      }    },    "rating": 3.7,    "url": "http://maps.google.com/maps/place?cid=11421630699047551449",    "icon": "http://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png",    "reference": "CkQ6AAAA03...hONadGmZ0",    "id": "ddf9cee27322c3bf"  },  "html_attributions": [ ]}

The JSON response contains three root elements:

  • "status" contains metadata on the request. See Status Codes below.
  • "result" contains the detailed information about the place requested. See Place Details Results for information about these results.
  • html_attributions contain a set of attributions about this listing which must be displayed to the user.

See Parsing JSON for some recommended design patterns.

Place Details XML Output

You may optionally request XML results within a Place Details request using the /xml output flag. A sample XML request is shown below, performing an identical Place Details request as shown in the JSON example above:

1 http://maps.google.com/maps/api/place/details/xml?reference=REFERENCE_ID&client=clientId&sensor=true_or_false&signature=SIGNATURE

The XML returned by this request is shown below.

1 <PlaceDetailsResponse>  <status>OK</status>  <result>   <name>Peter Luger Steakhouse</name>   <vicinity>Broadway, Brooklyn</vicinity>   <type>restaurant</type>   <type>food</type>   <type>establishment</type>   <formatted_phone_number>(718) 387-7400</formatted_phone_number>   <formatted_address>178 Broadway, Brooklyn, New York 11211, United States</formatted_address>   <address_component>    <long_name>178</long_name>    <short_name>178</short_name>    <type>street_number</type>   </address_component>   <address_component>    <long_name>Broadway</long_name>    <short_name>Broadway</short_name>    <type>route</type>   </address_component>   <address_component>    <long_name>Brooklyn</long_name>    <short_name>Brooklyn</short_name>    <type>locality</type>    <type>political</type>   </address_component>   <address_component>    <long_name>Kings</long_name>    <short_name>Kings</short_name>    <type>administrative_area_level_2</type>    <type>political</type>   </address_component>   <address_component>    <long_name>New York</long_name>    <short_name>New York</short_name>    <type>administrative_area_level_1</type>    <type>political</type>   </address_component>   <address_component>    <long_name>11211</long_name>    <short_name>11211</short_name>    <type>postal_code</type>   </address_component>   <geometry>    <location>     <lat>40.7099090</lat>     <lng>-73.9625800</lng>    </location>   </geometry>   <rating>3.7</rating>   <url>http://maps.google.com/maps/place?cid=11421630699047551449</url>   <icon>http://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png</icon>   <reference>CkQ6AAAAd...4oT4Sof9RHoGD4</reference>   <id>ddf9cee27322c3bf</id>  </result> </PlaceDetailsResponse>

Note that the XML response consists of a single <PlaceDetailsResponse> and three top-level elements:

  • <status> contains metadata on the request. See Status Codes below.
  • A single <result> element containing detailed information about a single establishment. See Place Details Results for information about these results.
  • <html_attributions> contain a set of attributions which must be displayed to the user.

See Parsing XML with XPath for some recommended design patterns for output processing.

Status Codes

The "status" field within the Place response object contains the status of the request, and may contain debugging information to help you track down why the Place request failed. The "status" field may contain the following values:

  • "OK" indicates that no errors occurred; the place was successfully detected and at least one result was returned.
  • "ZERO_RESULTS" indicates that the reference was valid but no longer refers to a valid result. This may occur if the establishment is no longerin business.
  • "OVER_QUERY_LIMIT" indicates that you are over your quota.
  • "REQUEST_DENIED" indicates that your request was denied, generally because of lack of a sensor parameter.
  • "INVALID_REQUEST" generally indicates that the query (reference) is missing or expired.

Place Details Results

When the Places service returns results from a details request, it places them within a single result. Each result may contain the following fields:

  • name contains the human-readable name for the returned result. For establishment results, this is usually the canonicalized business name.
  • vicinity contains a feature name of a nearby location. Often this feature refers to a street or neighborhood within the given results. This vicinity can be used to further refine results or disambiguate similar results.
  • types[] contains an array of feature types describing the given result. See Place Feature Types for more information.
  • formatted_phone_number contains a human-readable phone number.
  • formatted_address is a string containing the human-readable address of this place. Often this address is equivalent to the "postal address," which sometimes differs from country to country. (Note that some countries, such as the United Kingdom, do not allow distribution of true postal addresses due to licensing restrictions.) This address is generally composed of one or more address components. For example, the address "111 8th Avenue, New York, NY" contains separate address components for "111" (the street number, "8th Avenue" (the route), "New York" (the city) and "NY" (the US state). These address components contain additional information as noted below.

  • address_components[] is an array of separate address components used to compose a given address. For example, the address "111 8th Avenue, New York, NY" contains separate address components for "111" (the street number, "8th Avenue" (the route), "New York" (the city) and "NY" (the US state). Each address_component typically contains:

    • types[] is an array indicating the type of the address component.
    • long_name is the full text description or name of the address component as returned by the Geocoder.
    • short_name is an abbreviated textual name for the address component, if available. For example, an address component for the state of Alaska may have a long_name of "Alaska" and a short_name of "AK" using the 2-letter postal abbreviation.
  • geometry contains the following information:

    • location contains the geocoded latitude,longitude value for this place.
  • url contains the official Google Place Page URL of this establishment, which must be linked to from the Place's name when displaying this Place to the user.
  • rating contains the average user rating for this establishment based on the reviews shown on Google Maps, which are provided by a number of Google partners and websites.
  • icon contains the URL of a suggested icon which may be displayed to the user when indicating this result on a map
  • reference contains a permanent token about this place. Note that unlike a reference returned in a Place Search request, this reference token is stable and does not expire. However, although this token uniquely identifies the place, the converse is not true: a place may have many valid reference tokens.
  • id contains a unique stable identifier denoting this place. This identifier may not be used to retrieve information about this place, but this id is guaranteed to be valid across sessions, so you can use it to consolidate data about this place, and verify the identity of a Place across separate searches.

May 25 / 7:25am

CloudMade Makes Maps Differently

CloudMade Makes Maps Differently

CloudMade helps you make the most of map data. We source our maps from OpenStreetMap, the community mapping project which is making a free map of the world. Our aim is to continue the democratization of geo data and to expand access to open geo data through a range of simple yet powerful tools and APIs.

Our tools and APIs allow developers to create rich interactive experiences on the web and mobile.

Find out more

CloudMade Wins 'Best Emerging Startup' at Mobile World Congress

Latest Blog Entries

CloudMade Services Are Now Free – Sign Up Today

If you are a mobile or web developer – we have good news! As of today, when you sign up for a CloudMade developer account all of our services will be free of charge and will let you make money with loca...

Find out more

Past Events

Past Events

More info from recent events.

© 2008-2010 CloudMade. Map data © 2010 OpenStreetMap.org contributors Terms and Conditions Privacy Policy