Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 从位于巴林的地址提取区块编号_Android_Google Maps - Fatal编程技术网

Android 从位于巴林的地址提取区块编号

Android 从位于巴林的地址提取区块编号,android,google-maps,Android,Google Maps,我想知道巴林一个地址的区号 首先,让我告诉你什么是块数。 巴林被划分为多个区域,每个区域都有自己的区块编号,如图所示 所以,我希望你现在能弄清楚街区号 我已经实现了一个基本的应用程序来获取位置和它的一些信息,就像这样 此地址位于块326中,但我不知道如何获得正确的块编号 此功能已内置于Uber和trycarriage应用程序中 我正在使用谷歌的API获取我的数据 那么,关于如何做到这一点,有什么好主意吗?您可以使用地理编码API: https://maps.googleapis.com/ma

我想知道巴林一个地址的区号

首先,让我告诉你什么是块数。 巴林被划分为多个区域,每个区域都有自己的区块编号,如图所示

所以,我希望你现在能弄清楚街区号

我已经实现了一个基本的应用程序来获取位置和它的一些信息,就像这样

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

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

我正在使用谷歌的API获取我的数据

那么,关于如何做到这一点,有什么好主意吗?

您可以使用地理编码API:

https://maps.googleapis.com/maps/api/geocode/json?latlng=,&key=

并解析其JSON结果。例如

https://maps.googleapis.com/maps/api/geocode/json?latlng=26.218588,50.587587&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"
}
您可以在其中找到块名,例如在
“格式化的\u地址”
标记处:

“格式化地址”:“巴林麦纳麦326区块”

因此,您只需仔细解析JSON响应。

您可以使用地理编码API:

https://maps.googleapis.com/maps/api/geocode/json?latlng=,&key=

并解析其JSON结果。例如

https://maps.googleapis.com/maps/api/geocode/json?latlng=26.218588,50.587587&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"
}
您可以在其中找到块名,例如在
“格式化的\u地址”
标记处:

“格式化地址”:“巴林麦纳麦326区块”


所以,您只需要仔细解析JSON响应。

请不要写下错误,而是写下错误所在。您不需要指明您使用的地理数据源。如果你使用的是谷歌的API,你显示的是客户级别的地图视图(可能是谷歌地图截图),而不是API的结果。这是谷歌地图,我只是在我的android studioplease中构建了这个示例,而不是写下错误。你没有指出你使用的是什么地理数据源。如果你使用的是谷歌的API,你显示的是客户级别的地图视图(可能是谷歌地图截图),而不是API的结果。这是谷歌地图,我刚刚在android studioman中创建了这个示例,我必须让我的Gmail acc付费才能使用地理编码吗?@MoustafEL Saghier如果你每月信用额度在200美元以内-不。更多详细信息。先生,请问这可以在OSM上完成吗?OSM=>打开街道地图。@MoustafaEL Saghier请创建单独的问题。有没有关于用特定语言回复的提示?伙计,我必须让我的Gmail acc支付使用地理编码的费用吗?@MoustafEL Saghier,如果你每月信用额度在200美元以内-没有。更多详细信息。先生,请问这可以在OSM上完成吗?OSM=>Open Street Map.@MoustafaEL Saghier请创建单独的问题。是否有任何关于用特定语言做出响应的提示?