Windows Phone における地域設定とその取得

#wpdev_jp

アプリケーションでデバイスの地域を取得するにはどうしたらいいか?

image image

Windows Phone の言語と地域にはいくつかの設定があり、それぞれは異なる意味を持つ

  • 電話の言語:表示言語
  • 国/地域:国の設定だがMarketplaceの地域は Windows Account に紐づいているのでこれとは関係ない。尚これを設定するとある程度自動的に下の「地域設定」も連動して変更される(地域設定だけ別途変更可能)
  • 地域設定:実際に使用している地域や、日付や時間、通貨の表示設定
  • ブラウザーと検索に使用する言語:文字通りブラウザの検索に使用する言語

そして上記設定の値をアプリケーションから取得するAPIはこちら

  • 電話の言語:System.Globalization.CultureInfo.CurrentUICulture
  • 国/地域:たぶんなし
  • 地域設定:System.Globalization.RegionInfo.CurrentRegion, System.Globalization.CultureInfo.CurrentCulture
  • ブラウザーと検索に使用する言語:たぶんなし

見てわかる通り、結局あくまでもユーザーが設定するもので、実際にそこにいるという保証はないもの。本当に実際の一がほしいのであればGPSの位置情報をもとに取得するしかない。

Google Map のこんなWeb サービスもある。

https://maps.googleapis.com/maps/api/geocode/json?latlng=latitiude,longitude&sensor=true

こんな感じ。

https://maps.googleapis.com/maps/api/geocode/json?latlng=35.6266,139.7404&sensor=true

JSONで戻り値をもらえる。

 {
   "results" : [
      {
         "address_components" : [
            {
               "long_name" : "4",
               "short_name" : "4",
               "types" : [ "sublocality_level_4", "sublocality", "political" ]
            },
            {
               "long_name" : "16",
               "short_name" : "16",
               "types" : [ "sublocality_level_3", "sublocality", "political" ]
            },
            {
               "long_name" : "2丁目",
               "short_name" : "2丁目",
               "types" : [ "sublocality_level_2", "sublocality", "political" ]
            },
            {
               "long_name" : "港南",
               "short_name" : "港南",
               "types" : [ "sublocality_level_1", "sublocality", "political" ]
            },
            {
               "long_name" : "港区",
               "short_name" : "港区",
               "types" : [ "locality", "political" ]
            },
            {
               "long_name" : "東京都",
               "short_name" : "東京都",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "日本",
               "short_name" : "JP",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "日本, 東京都港区港南2丁目16−4",
         "geometry" : {
            "location" : {
               "lat" : 35.6266743,
               "lng" : 139.740443
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 35.6280232802915,
                  "lng" : 139.7417919802915
               },
               "southwest" : {
                  "lat" : 35.6253253197085,
                  "lng" : 139.7390940197085
               }
            }
         },
         "types" : [ "sublocality_level_4", "sublocality", "political" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "108-8240",
               "short_name" : "108-8240",
               "types" : [ "postal_code" ]
            },
            {
               "long_name" : "日本",
               "short_name" : "JP",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "〒108-8240, 日本",
         "geometry" : {
            "location" : {
               "lat" : 35.6266132,
               "lng" : 139.7404041
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 35.6279621802915,
                  "lng" : 139.7417530802915
               },
               "southwest" : {
                  "lat" : 35.62526421970851,
                  "lng" : 139.7390551197085
               }
            }
         },
         "types" : [ "postal_code" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "108-8228",
               "short_name" : "108-8228",
               "types" : [ "postal_code" ]
            },
            {
               "long_name" : "日本",
               "short_name" : "JP",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "〒108-8228, 日本",
         "geometry" : {
            "location" : {
               "lat" : 35.6266215,
               "lng" : 139.7404291
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 35.62797048029149,
                  "lng" : 139.7417780802915
               },
               "southwest" : {
                  "lat" : 35.6252725197085,
                  "lng" : 139.7390801197085
               }
            }
         },
         "types" : [ "postal_code" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "108-8117",
               "short_name" : "108-8117",
               "types" : [ "postal_code" ]
            },
            {
               "long_name" : "日本",
               "short_name" : "JP",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "〒108-8117, 日本",
         "geometry" : {
            "location" : {
               "lat" : 35.6266076,
               "lng" : 139.7404402
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 35.6279565802915,
                  "lng" : 139.7417891802915
               },
               "southwest" : {
                  "lat" : 35.6252586197085,
                  "lng" : 139.7390912197085
               }
            }
         },
         "types" : [ "postal_code" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "108-8202",
               "short_name" : "108-8202",
               "types" : [ "postal_code" ]
            },
            {
               "long_name" : "日本",
               "short_name" : "JP",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "〒108-8202, 日本",
         "geometry" : {
            "location" : {
               "lat" : 35.6266354,
               "lng" : 139.7404041
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 35.62798438029149,
                  "lng" : 139.7417530802915
               },
               "southwest" : {
                  "lat" : 35.6252864197085,
                  "lng" : 139.7390551197085
               }
            }
         },
         "types" : [ "postal_code" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "108-8248",
               "short_name" : "108-8248",
               "types" : [ "postal_code" ]
            },
            {
               "long_name" : "日本",
               "short_name" : "JP",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "〒108-8248, 日本",
         "geometry" : {
            "location" : {
               "lat" : 35.6266382,
               "lng" : 139.740368
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 35.62798718029149,
                  "lng" : 139.7417169802915
               },
               "southwest" : {
                  "lat" : 35.6252892197085,
                  "lng" : 139.7390190197085
               }
            }
         },
         "types" : [ "postal_code" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "108-8242",
               "short_name" : "108-8242",
               "types" : [ "postal_code" ]
            },
            {
               "long_name" : "日本",
               "short_name" : "JP",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "〒108-8242, 日本",
         "geometry" : {
            "location" : {
               "lat" : 35.6266382,
               "lng" : 139.7404402
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 35.62798718029149,
                  "lng" : 139.7417891802915
               },
               "southwest" : {
                  "lat" : 35.6252892197085,
                  "lng" : 139.7390912197085
               }
            }
         },
         "types" : [ "postal_code" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "108-8241",
               "short_name" : "108-8241",
               "types" : [ "postal_code" ]
            },
            {
               "long_name" : "日本",
               "short_name" : "JP",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "〒108-8241, 日本",
         "geometry" : {
            "location" : {
               "lat" : 35.6266965,
               "lng" : 139.7404069
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 35.6280454802915,
                  "lng" : 139.7417558802915
               },
               "southwest" : {
                  "lat" : 35.62534751970851,
                  "lng" : 139.7390579197085
               }
            }
         },
         "types" : [ "postal_code" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "108-8217",
               "short_name" : "108-8217",
               "types" : [ "postal_code" ]
            },
            {
               "long_name" : "日本",
               "short_name" : "JP",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "〒108-8217, 日本",
         "geometry" : {
            "location" : {
               "lat" : 35.6271687,
               "lng" : 139.740518
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 35.6285176802915,
                  "lng" : 139.7418669802915
               },
               "southwest" : {
                  "lat" : 35.6258197197085,
                  "lng" : 139.7391690197085
               }
            }
         },
         "types" : [ "postal_code" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "108-8222",
               "short_name" : "108-8222",
               "types" : [ "postal_code" ]
            },
            {
               "long_name" : "日本",
               "short_name" : "JP",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "〒108-8222, 日本",
         "geometry" : {
            "location" : {
               "lat" : 35.6271742,
               "lng" : 139.7404791
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 35.6285231802915,
                  "lng" : 139.7418280802915
               },
               "southwest" : {
                  "lat" : 35.6258252197085,
                  "lng" : 139.7391301197085
               }
            }
         },
         "types" : [ "postal_code" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "108-8220",
               "short_name" : "108-8220",
               "types" : [ "postal_code" ]
            },
            {
               "long_name" : "日本",
               "short_name" : "JP",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "〒108-8220, 日本",
         "geometry" : {
            "location" : {
               "lat" : 35.6271715,
               "lng" : 139.7405068
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 35.62852048029149,
                  "lng" : 139.7418557802915
               },
               "southwest" : {
                  "lat" : 35.6258225197085,
                  "lng" : 139.7391578197085
               }
            }
         },
         "types" : [ "postal_code" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "16",
               "short_name" : "16",
               "types" : [ "sublocality_level_3", "sublocality", "political" ]
            },
            {
               "long_name" : "2丁目",
               "short_name" : "2丁目",
               "types" : [ "sublocality_level_2", "sublocality", "political" ]
            },
            {
               "long_name" : "港南",
               "short_name" : "港南",
               "types" : [ "sublocality_level_1", "sublocality", "political" ]
            },
            {
               "long_name" : "港区",
               "short_name" : "港区",
               "types" : [ "locality", "political" ]
            },
            {
               "long_name" : "東京都",
               "short_name" : "東京都",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "日本",
               "short_name" : "JP",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "日本, 東京都港区港南2丁目16",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 35.6285005,
                  "lng" : 139.7417164
               },
               "southwest" : {
                  "lat" : 35.6246998,
                  "lng" : 139.7393846
               }
            },
            "location" : {
               "lat" : 35.6249245,
               "lng" : 139.7405264
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 35.6285005,
                  "lng" : 139.7418994802915
               },
               "southwest" : {
                  "lat" : 35.6246998,
                  "lng" : 139.7392015197085
               }
            }
         },
         "types" : [ "sublocality_level_3", "sublocality", "political" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "北品川駅",
               "short_name" : "北品川駅",
               "types" : [ "train_station", "transit_station", "establishment" ]
            },
            {
               "long_name" : "東京都",
               "short_name" : "東京都",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "日本",
               "short_name" : "JP",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "日本, 北品川駅(東京)",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 35.62729900000001,
                  "lng" : 139.745705
               },
               "southwest" : {
                  "lat" : 35.618074,
                  "lng" : 139.731772
               }
            },
            "location" : {
               "lat" : 35.622716,
               "lng" : 139.739152
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 35.62729900000001,
                  "lng" : 139.745705
               },
               "southwest" : {
                  "lat" : 35.618074,
                  "lng" : 139.731772
               }
            }
         },
         "types" : [ "train_station", "transit_station", "establishment" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "2丁目",
               "short_name" : "2丁目",
               "types" : [ "sublocality_level_2", "sublocality", "political" ]
            },
            {
               "long_name" : "港南",
               "short_name" : "港南",
               "types" : [ "sublocality_level_1", "sublocality", "political" ]
            },
            {
               "long_name" : "港区",
               "short_name" : "港区",
               "types" : [ "locality", "political" ]
            },
            {
               "long_name" : "東京都",
               "short_name" : "東京都",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "日本",
               "short_name" : "JP",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "日本, 東京都港区港南2丁目",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 35.6388674,
                  "lng" : 139.7463331
               },
               "southwest" : {
                  "lat" : 35.6231308,
                  "lng" : 139.7376797
               }
            },
            "location" : {
               "lat" : 35.6292102,
               "lng" : 139.7425232
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 35.6388674,
                  "lng" : 139.7463331
               },
               "southwest" : {
                  "lat" : 35.6231308,
                  "lng" : 139.7376797
               }
            }
         },
         "types" : [ "sublocality_level_2", "sublocality", "political" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "品川駅",
               "short_name" : "品川駅",
               "types" : [ "train_station", "transit_station", "establishment" ]
            },
            {
               "long_name" : "東京都",
               "short_name" : "東京都",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "日本",
               "short_name" : "JP",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "日本, 品川駅(東京)",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 35.638322,
                  "lng" : 139.752131
               },
               "southwest" : {
                  "lat" : 35.621305,
                  "lng" : 139.729543
               }
            },
            "location" : {
               "lat" : 35.630152,
               "lng" : 139.74044
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 35.638322,
                  "lng" : 139.752131
               },
               "southwest" : {
                  "lat" : 35.621305,
                  "lng" : 139.729543
               }
            }
         },
         "types" : [ "train_station", "transit_station", "establishment" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "108-0075",
               "short_name" : "108-0075",
               "types" : [ "postal_code" ]
            },
            {
               "long_name" : "港南",
               "short_name" : "港南",
               "types" : [ "sublocality_level_1", "sublocality", "political" ]
            },
            {
               "long_name" : "港区",
               "short_name" : "港区",
               "types" : [ "locality", "political" ]
            },
            {
               "long_name" : "東京都",
               "short_name" : "東京都",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "日本",
               "short_name" : "JP",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "〒108-0075, 日本",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 35.6377699,
                  "lng" : 139.7600968
               },
               "southwest" : {

                  "lat" : 35.6209329,
                  "lng" : 139.7371014
               }
            },
            "location" : {
               "lat" : 35.6292102,
               "lng" : 139.7425232
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 35.6377699,
                  "lng" : 139.7600968
               },
               "southwest" : {
                  "lat" : 35.6209329,
                  "lng" : 139.7371014
               }
            }
         },
         "types" : [ "postal_code" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "港南",
               "short_name" : "港南",
               "types" : [ "sublocality_level_1", "sublocality", "political" ]
            },
            {
               "long_name" : "港区",
               "short_name" : "港区",
               "types" : [ "locality", "political" ]
            },
            {
               "long_name" : "東京都",
               "short_name" : "東京都",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "日本",
               "short_name" : "JP",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "日本, 東京都港区港南",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 35.6388626,
                  "lng" : 139.7593943
               },
               "southwest" : {
                  "lat" : 35.6231238,
                  "lng" : 139.7376797
               }
            },
            "location" : {
               "lat" : 35.6292102,
               "lng" : 139.7425232
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 35.6388626,
                  "lng" : 139.7593943
               },
               "southwest" : {
                  "lat" : 35.6231238,
                  "lng" : 139.7376797
               }
            }
         },
         "types" : [ "sublocality_level_1", "sublocality", "political" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "港区",
               "short_name" : "港区",
               "types" : [ "locality", "political" ]
            },
            {
               "long_name" : "東京都",
               "short_name" : "東京都",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "日本",
               "short_name" : "JP",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "日本, 東京都港区",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 35.6825958,
                  "lng" : 139.7828356
               },
               "southwest" : {
                  "lat" : 35.6231224,
                  "lng" : 139.7087472
               }
            },
            "location" : {
               "lat" : 35.6580681,
               "lng" : 139.7515992
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 35.6825958,
                  "lng" : 139.7828356
               },
               "southwest" : {
                  "lat" : 35.6231224,
                  "lng" : 139.7087472
               }
            }
         },
         "types" : [ "locality", "political" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "東京都",
               "short_name" : "東京都",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "日本",
               "short_name" : "JP",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "日本, 東京都",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 35.8986441,
                  "lng" : 153.9875217
               },
               "southwest" : {
                  "lat" : 24.2242343,
                  "lng" : 138.942758
               }
            },
            "location" : {
               "lat" : 35.6894875,
               "lng" : 139.6917064
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 35.817813,
                  "lng" : 139.910202
               },
               "southwest" : {
                  "lat" : 35.528873,
                  "lng" : 139.510574
               }
            }
         },
         "types" : [ "administrative_area_level_1", "political" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "日本",
               "short_name" : "JP",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "日本",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 45.5227719,
                  "lng" : 153.9874306
               },
               "southwest" : {
                  "lat" : 24.0460446,
                  "lng" : 122.9338302
               }
            },
            "location" : {
               "lat" : 36.204824,
               "lng" : 138.252924
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 45.5227719,
                  "lng" : 145.8175503
               },
               "southwest" : {
                  "lat" : 24.0486928,
                  "lng" : 122.9338302
               }
            }
         },
         "types" : [ "country", "political" ]
      }
   ],
   "status" : "OK"
}