Reputation: 524
I've tried Googling and checking the documentation for the Google Places JavaScript API but haven't been able to find an answer to this question.
When I perform a search for a specific city, like San Francisco, CA, I get a response that looks like this:
/**/_xdc_._a1fter && _xdc_._a1fter( {
"html_attributions" : [],
"result" : {
"address_components" : [
{
"long_name" : "San Francisco",
"short_name" : "SF",
"types" : [ "locality", "political" ]
},
{
"long_name" : "San Francisco County",
"short_name" : "San Francisco County",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "California",
"short_name" : "CA",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
}
],
"adr_address" : "\u003cspan class=\"locality\"\u003eSan Francisco\u003c/span\u003e, \u003cspan class=\"region\"\u003eCA\u003c/span\u003e, \u003cspan class=\"country-name\"\u003eUSA\u003c/span\u003e",
"formatted_address" : "San Francisco, CA, USA",
"geometry" : {
"location" : {
"lat" : 37.7749295,
"lng" : -122.4194155
},
"viewport" : {
"northeast" : {
"lat" : 37.812,
"lng" : -122.3482
},
"southwest" : {
"lat" : 37.70339999999999,
"lng" : -122.527
}
}
},
"icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png",
"id" : "1b9ea3c094d3ac23c9a3afa8cd4d8a41f05de50a",
"name" : "San Francisco",
"photos" : [
{
"height" : 2448,
"html_attributions" : [
"\u003ca href=\"https://maps.google.com/maps/contrib/103231451031314314785/photos\"\u003eTrigby Perea\u003c/a\u003e"
],
"raw_reference" : {
"fife_url" : "https://lh4.googleusercontent.com/-aP4oMIc1OZ0/V2g8WKNFqpI/AAAAAAAANbU/w0Ii2GYhpyofvMqPjzEH0RcL-KkdMblEQCLIB/k/"
},
"width" : 3264
},
{
"height" : 3651,
"html_attributions" : [
"\u003ca href=\"https://maps.google.com/maps/contrib/111642936581150005827/photos\"\u003eCraig Foster\u003c/a\u003e"
],
"raw_reference" : {
"fife_url" : "https://lh5.googleusercontent.com/-Fp-Ds7Nltp0/Vke8Hc4KbZI/AAAAAAAB3lg/Zyh3nNGV_ZMhm5zFXBxQk4fToCLikK2bQ/k/"
},
"width" : 5477
},
{
"height" : 1441,
"html_attributions" : [
"\u003ca href=\"https://maps.google.com/maps/contrib/105870396459094511944/photos\"\u003eAbbey Taylor\u003c/a\u003e"
],
"raw_reference" : {
"fife_url" : "https://lh5.googleusercontent.com/-zohVGEyuXoc/VlHp_eA5DnI/AAAAAAAARKc/pyOWLnMEJnActbiE-NGo8aRxmAnLmyTgA/k/"
},
"width" : 1920
},
{
"height" : 1520,
"html_attributions" : [
"\u003ca href=\"https://maps.google.com/maps/contrib/114911123719406241256/photos\"\u003eChristine Tallon\u003c/a\u003e"
],
"raw_reference" : {
"fife_url" : "https://lh6.googleusercontent.com/-4ImN1qnn6mg/V87uASQ2tOI/AAAAAAAAAH8/z_2yiFXWTdQsxG-RTTqC0_TKQROHDUkIACLIB/k/"
},
"width" : 2688
},
{
"height" : 1836,
"html_attributions" : [
"\u003ca href=\"https://maps.google.com/maps/contrib/111652642356832495715/photos\"\u003eLau Dora\u003c/a\u003e"
],
"raw_reference" : {
"fife_url" : "https://lh5.googleusercontent.com/-ylvq826HIy0/V5EgFJrFBjI/AAAAAAAAlj4/EGL_L-RflOgu6rTFVvFvUl8Wkxw3nnzJgCLIB/k/"
},
"width" : 3264
},
{
"height" : 1944,
"html_attributions" : [
"\u003ca href=\"https://maps.google.com/maps/contrib/112904178425011771283/photos\"\u003eGlenn Meyer\u003c/a\u003e"
],
"raw_reference" : {
"fife_url" : "https://lh3.googleusercontent.com/-daHOav_w_QY/V2WuYuir_1I/AAAAAAAAPso/RhsZzyz05ygoeu4kjL_4bbNEepSNn_auwCLIB/k/"
},
"width" : 3456
},
{
"height" : 2592,
"html_attributions" : [
"\u003ca href=\"https://maps.google.com/maps/contrib/110340141477234279592/photos\"\u003eZaw Khun Naw Hpunggan\u003c/a\u003e"
],
"raw_reference" : {
"fife_url" : "https://lh4.googleusercontent.com/-EjAUXW008Xo/Vmy-JD612FI/AAAAAAAAMMc/km2jOrx8-dwPYFHaTqfCw2PVMu5bQxZFA/k/"
},
"width" : 4608
},
{
"height" : 2988,
"html_attributions" : [
"\u003ca href=\"https://maps.google.com/maps/contrib/112146856900507552674/photos\"\u003eJustin Wah Kan\u003c/a\u003e"
],
"raw_reference" : {
"fife_url" : "https://lh6.googleusercontent.com/-Hk2UJFlS4HE/V2Q8KN1Q09I/AAAAAAABAMg/IFdiQdW1EfkQmIOkx_vZE1ZIQu-Oc80bQCLIB/k/"
},
"width" : 5312
},
{
"height" : 3024,
"html_attributions" : [
"\u003ca href=\"https://maps.google.com/maps/contrib/101062424435478354204/photos\"\u003eNitesh Misra\u003c/a\u003e"
],
"raw_reference" : {
"fife_url" : "https://lh6.googleusercontent.com/-KaFyc8uLu3E/V52S4rwKZ0I/AAAAAAAABNw/OoqMzR3BhWIEbP57UEYlxlhrc_JrjGZ0QCLIB/k/"
},
"width" : 4030
},
{
"height" : 3265,
"html_attributions" : [
"\u003ca href=\"https://maps.google.com/maps/contrib/101841506952017923314/photos\"\u003eAlejandro Villa Renteria\u003c/a\u003e"
],
"raw_reference" : {
"fife_url" : "https://lh3.googleusercontent.com/-d9HUyuzGUrI/VyDZ3QJAk1I/AAAAAAACAbk/PkZyTBaBQnI233l3sDWivzPKzFmhfBU9QCLIB/k/"
},
"width" : 4898
}
],
"place_id" : "ChIJIQBpAG2ahYAR_6128GcTUEo",
"reference" : "CoQBcwAAAPXngWwN52gpBv2Gpbi1kgRDZYEO6VclmIOEH8LyQKzEf8onqG72eVhCZSEoFLHpPmO2obfQRHO34oNkSprGBSZ4Mt0PvfUcABiPGKzmO2iALQPYh5pLv_3C6yst3Y-WZFq08ZHCBk5dOUo1o3HEyDjXwxE3gPIH9IXpfYvXCn5dEhCuC8FoVZo8pKqcMpm494tcGhTh80nRCEJD3U2Aozn3Tm83E8-_Jw",
"scope" : "GOOGLE",
"types" : [ "locality", "political" ],
"url" : "https://maps.google.com/?q=San+Francisco,+CA,+USA&ftid=0x80859a6d00690021:0x4a501367f076adff",
"utc_offset" : -420,
"vicinity" : "San Francisco"
},
"status" : "OK"
}
)
The specific part of this I'm curious about is this section:
"geometry" : {
"location" : {
"lat" : 37.7749295,
"lng" : -122.4194155
},
How does Google determine these latitude and longitude values for a Place like a City or County that's actually an area?
It doesn't appear to use the geographic center of the city or any other consistent method that I can discern, and I couldn't find this mentioned anywhere in the docs.
Upvotes: 3
Views: 843
Reputation: 4840
Let me answer with a question: why do you care?
Years ago, I remember Google Maps would drop a pin in front of the city hall when searching for a city. This was fairly consistent across several countries, at last the ones I'm somewhat familiar with (Spain, Ireland, UK, USA, ...) and I always wondered, why would I want any pin point anyway?
Looking at it now, Google Maps no longer drops a pin anywhere when you search for a city, instead it highlights the relevant area. I take this as a strong signal that the point location for a big place is probably not very useful. This may be also one of the reasons why this feature request is by far the most popular: https://code.google.com/p/gmaps-api-issues/issues/detail?id=109
The point center of some localities I'm familiar with seem to be prominent landmarks, which I reckon are quite representative of what most people would think as "the center" of those cities:
Others seem to have their center in a mere cross of main roads, as is the case in San Francisco and Zurich. Others, mostly in small towns, I can honestly not make sense of.
My take is that the center of a city or county only makes sense as a rough approximation of what people would point at as the downtown area, in a city, or where most people live, in an big unevenly/sparsely populated area. Such point would only be useful at a low zoom level.
This seems somewhat consistent with the idea that a city or a county does not really have a "center" as such, a single point where absolutely everybody would put the finger to say "here, is this is the heart of this city".
But even if/when there is such a point, it may not always be what you're looking for. For instance, if you're traveling between cities by train, you probably care not for such points, but rather care for their train stations.
Example: transit directions from San Jose to San Francisco return a route that starts at the San Jose Diridon Station (37.33068,-121.902382) and ends at the San Francisco Station (37.776687,-122.394857), because those are the relevant points for each city in this context.
Upvotes: 3