从位于巴林的地址中提取块号 [英] extract block number from address located in Bahrain

查看:34
本文介绍了从位于巴林的地址中提取块号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获取位于巴林的地址的阻止号码.

I wanna get the block number of an address located in Bahrain.

首先,让我告诉您什么是块号.巴林分为几个区域,每个区域都有其区块编号,如照片中所示.

first of all, let me show you what is block numbers. Bahrain is divided into areas and each area has its block number like in the photo.

所以,我希望您现在能清楚看到块号.

so, I hope the block number becomes clear to you now.

我已经实现了一个基本的应用程序来获取位置及其类似信息

I've implemented a basic app to get the location and some of its info like this

此地址位于 BLOCK 326 中,但是我不知道如何获取正确的块编号.

this address is located in BLOCK 326 but I don't have any idea about how getting the correct block num.

此功能已经内置于 Uber trycarriage 应用程序中.

this feature is already built-in Uber and trycarriage apps.

我正在使用Google的API来获取数据.

I'm using Google's API to get my data.

那么,关于如何做到的任何好主意?

so, any good ideas about how could that be done?

推荐答案

您可以使用 https://maps.googleapis.com/maps/api/geocode/json?latlng=<LATITUDE> ;,< LONGITURE>& key =<您的API_KEY>

并解析其JSON结果.例如

and parse its JSON result. For example for

https://maps.googleapis.com/maps/api/geocode/json?latlng=26.218588,50.587587& key =< YOUR_API_KEY>

你有类似的东西:

{
   "plus_code" : {
      "compound_code" : "6H9Q+C2 Manama, Bahrain",
      "global_code" : "7HRG6H9Q+C2"
   },
   "results" : [
      {
         "address_components" : [
            {
               "long_name" : "Bahrain",
               "short_name" : "BH",
               "types" : [ "country", "political" ]
            },
            {
               "long_name" : "القضيبية",
               "short_name" : "القضيبية",
               "types" : [ "political", "sublocality", "sublocality_level_1" ]
            },
            {
               "long_name" : "المنامة",
               "short_name" : "المنامة",
               "types" : [ "locality", "political" ]
            },
            {
               "long_name" : "محافظة العاصمة",
               "short_name" : "محافظة العاصمة",
               "types" : [ "administrative_area_level_1", "political" ]
            }
         ],
         "formatted_address" : "Road 596, Build 326 , Flat 12 - Adliya , Bahrain, المنامة، Bahrain",
         "geometry" : {
            "location" : {
               "lat" : 26.218734,
               "lng" : 50.587591
            },
            "location_type" : "GEOMETRIC_CENTER",
            "viewport" : {
               "northeast" : {
                  "lat" : 26.2200829802915,
                  "lng" : 50.5889399802915
               },
               "southwest" : {
                  "lat" : 26.21738501970849,
                  "lng" : 50.5862420197085
               }
            }
         },
         "place_id" : "ChIJf7pq3DevST4RM9wS0YnAkGk",
         "plus_code" : {
            "compound_code" : "6H9Q+F2 Manama, Bahrain",
            "global_code" : "7HRG6H9Q+F2"
         },
         "types" : [ "establishment", "point_of_interest" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "Hassan Bin Thabit Avenue",
               "short_name" : "Hassan Bin Thabit Ave",
               "types" : [ "route" ]
            },
            {
               "long_name" : "Qudaibiya",
               "short_name" : "Qudaibiya",
               "types" : [ "political", "sublocality", "sublocality_level_1" ]
            },
            {
               "long_name" : "Manama",
               "short_name" : "Manama",
               "types" : [ "locality", "political" ]
            },
            {
               "long_name" : "Capital Governorate",
               "short_name" : "Capital Governorate",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "Bahrain",
               "short_name" : "BH",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "Hassan Bin Thabit Ave, Manama, Bahrain",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 26.218572,
                  "lng" : 50.58771420000001
               },
               "southwest" : {
                  "lat" : 26.2184482,
                  "lng" : 50.5874591
               }
            },
            "location" : {
               "lat" : 26.2185067,
               "lng" : 50.5875887
            },
            "location_type" : "GEOMETRIC_CENTER",
            "viewport" : {
               "northeast" : {
                  "lat" : 26.2198590802915,
                  "lng" : 50.5889356302915
               },
               "southwest" : {
                  "lat" : 26.2171611197085,
                  "lng" : 50.5862376697085
               }
            }
         },
         "place_id" : "ChIJyekp3TevST4Rfj8TaosVDpE",
         "types" : [ "route" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "Block 326",
               "short_name" : "Block 326",
               "types" : [ "neighborhood", "political" ]
            },
            {
               "long_name" : "Qudaibiya",
               "short_name" : "Qudaibiya",
               "types" : [ "political", "sublocality", "sublocality_level_1" ]
            },
            {
               "long_name" : "Manama",
               "short_name" : "Manama",
               "types" : [ "locality", "political" ]
            },
            {
               "long_name" : "Capital Governorate",
               "short_name" : "Capital Governorate",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "Bahrain",
               "short_name" : "BH",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "Block 326, Manama, Bahrain",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 26.2234075,
                  "lng" : 50.5912257
               },
               "southwest" : {
                  "lat" : 26.2153032,
                  "lng" : 50.5850888
               }
            },
            "location" : {
               "lat" : 26.2198723,
               "lng" : 50.5879925
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 26.2234075,
                  "lng" : 50.5912257
               },
               "southwest" : {
                  "lat" : 26.2153032,
                  "lng" : 50.5850888
               }
            }
         },
         "place_id" : "ChIJb9O71TevST4RqB02rRcRh1g",
         "types" : [ "neighborhood", "political" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "Qudaibiya",
               "short_name" : "Qudaibiya",
               "types" : [ "political", "sublocality", "sublocality_level_1" ]
            },
            {
               "long_name" : "Manama",
               "short_name" : "Manama",
               "types" : [ "locality", "political" ]
            },
            {
               "long_name" : "Capital Governorate",
               "short_name" : "Capital Governorate",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "Bahrain",
               "short_name" : "BH",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "Qudaibiya, Manama, Bahrain",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 26.2297388,
                  "lng" : 50.59774059999999
               },
               "southwest" : {
                  "lat" : 26.2077109,
                  "lng" : 50.5822785
               }
            },
            "location" : {
               "lat" : 26.2186782,
               "lng" : 50.5938215
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 26.2297388,
                  "lng" : 50.59774059999999
               },
               "southwest" : {
                  "lat" : 26.2077109,
                  "lng" : 50.5822785
               }
            }
         },
         "place_id" : "ChIJic3RMUivST4Ru9BNKfSYXcw",
         "types" : [ "political", "sublocality", "sublocality_level_1" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "Manama",
               "short_name" : "Manama",
               "types" : [ "locality", "political" ]
            },
            {
               "long_name" : "Capital Governorate",
               "short_name" : "Capital Governorate",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "Bahrain",
               "short_name" : "BH",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "Manama, Bahrain",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 26.262323,
                  "lng" : 50.62693119999999
               },
               "southwest" : {
                  "lat" : 26.1909103,
                  "lng" : 50.5511212
               }
            },
            "location" : {
               "lat" : 26.2235305,
               "lng" : 50.5875935
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 26.262323,
                  "lng" : 50.62693119999999
               },
               "southwest" : {
                  "lat" : 26.1909103,
                  "lng" : 50.5511212
               }
            }
         },
         "place_id" : "ChIJLaZ2J3KvST4RwmAPB6Y4Z4s",
         "types" : [ "locality", "political" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "Capital Governorate",
               "short_name" : "Capital Governorate",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "Bahrain",
               "short_name" : "BH",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "Capital Governorate, Bahrain",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 26.262323,
                  "lng" : 50.62693119999999
               },
               "southwest" : {
                  "lat" : 26.1909103,
                  "lng" : 50.51370679999999
               }
            },
            "location" : {
               "lat" : 26.2285161,
               "lng" : 50.5860497
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 26.262323,
                  "lng" : 50.62693119999999
               },
               "southwest" : {
                  "lat" : 26.1909103,
                  "lng" : 50.51370679999999
               }
            }
         },
         "place_id" : "ChIJo5Ng-m-vST4RGbXeFQV4px4",
         "types" : [ "administrative_area_level_1", "political" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "Bahrain",
               "short_name" : "BH",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "Bahrain",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 26.3469001,
                  "lng" : 50.8509064
               },
               "southwest" : {
                  "lat" : 25.5349999,
                  "lng" : 50.324246
               }
            },
            "location" : {
               "lat" : 26.0667,
               "lng" : 50.5577
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 26.3469001,
                  "lng" : 50.8509064
               },
               "southwest" : {
                  "lat" : 25.5349999,
                  "lng" : 50.324246
               }
            }
         },
         "place_id" : "ChIJEaJHak5SSD4RRhDa2-JQlC4",
         "types" : [ "country", "political" ]
      }
   ],
   "status" : "OK"
}

您可以在其中找到块名称,例如在"formatted_address" 标记处:

where you can find block name e.g. at "formatted_address" tag:

"formatted_address":巴林麦纳麦326街区",

因此,您只需要仔细解析JSON响应即可.

So, you just need to carefully parse JSON response.

这篇关于从位于巴林的地址中提取块号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆