在android中找到离地理点最近的警察局

Posted

技术标签:

【中文标题】在android中找到离地理点最近的警察局【英文标题】:Find a police station nearest to a geopoint in android 【发布时间】:2012-09-05 10:36:35 【问题描述】:

如何在android中找到离地理点最近的特定地区的警察局

【问题讨论】:

我知道的一种方法是您可以使用 GooglePlace Search Api 来实现。看到这个:Google Place Search API 这里mobile.tutsplus.com/tutorials/android/… 是一个很好的例子,可以帮助您找到最近的购物中心...通过参考这个您可以找到最近的警察局。 【参考方案1】:

您需要 Google Place API。

赞:https://maps.googleapis.com/maps/api/place/search/json?location=37.785835,-122.406418&rankby=distance&types=police&sensor=false&key="你的 google api 密钥"

它会从给定位置给你派出所:

例如:



    "html_attributions": [ ],
    "next_page_token": "ClROAAAAuha4O-3EU2bv3HEZWC4uCwnBGNN1REl5DJmvwwGTXdIpLJJIoAjZCo7Oz3WhkVFPsrTokqCYMvoiBpsgkOtLhPApA39yG1x6HbCrUANTFB8SEO2_p9pOH43PRzuvBY6HrhwaFMRc_HgRPSM6DXi5PjVgBHS2L0Sg",
    "results": [
        
            "geometry": 
                "location": 
                    "lat": 37.789787,
                    "lng": -122.404926
                
            ,
            "icon": "http://maps.gstatic.com/mapfiles/place_api/icons/police-71.png",
            "id": "e71eefdf4bb6f83053f77b6e912d3b0c93e70a07",
            "name": "Storefront Political Media",
            "reference": "CoQBeAAAALpR5H-3V8s-aWoozSfB7azhDcXMxYnQ1tf1KenvFN4hqw_xDkHgZqtwQu6zZIDm_Idx_6mx0RMDVwD6kG0lXguSw2uZxKUjQqZ94s3XRu1tSE4bPQFlHSdgCvYEXYf84DcG7-rkR4bTFxvkzrfOOhGAkm3nvJ1jsQWpAam8tSLEEhCQuzeLxsdfvLWVr8gwsEYkGhTQ2LqvI7BQER8ZBjK-6Vn2zKA7Ow",
            "types": [
                "police",
                "establishment"
            ],
            "vicinity": "250 Sutter Street, San Francisco"
        ,
        
            "geometry": 
                "location": 
                    "lat": 37.78386,
                    "lng": -122.412462
                
            ,
            "icon": "http://maps.gstatic.com/mapfiles/place_api/icons/police-71.png",
            "id": "a387ed44c75e75b602623c5c4601acde59e2e093",
            "name": "San Francisco Police Department",
            "reference": "CoQBfQAAAIHa4qugT0fvLQVpOZNnwI8rp1mNW2pwK7_-nLO10SOa9fdPGo2CPMFtehB5oKDT1EICYQIerGlcHln556HaTBKfXaL1MMmb0X_73SwClAYSTw1k0V90nbICrTYzcXt2F6jz2C9oC13-7_jVyVAWJ77Vo1i8SwIcN_OkjdLKjgEeEhBP0MaxKVM_UK5Q5nGVts-cGhSeCbb2llu_ab8rC1FMbxswyXFEwg",
            "types": [
                "local_government_office",
                "police",
                "establishment"
            ],
            "vicinity": "301 Eddy Street, San Francisco"
        ,
        
            "geometry": 
                "location": 
                    "lat": 37.783812,
                    "lng": -122.412728
                
            ,
            "icon": "http://maps.gstatic.com/mapfiles/place_api/icons/police-71.png",
            "id": "7a74ae30f53f5e6d64c16407c413e54e236ec50a",
            "name": "San Francisco Police Department Force; Tenderloin",
            "reference": "CpQBkAAAAPpjzuyg29pyo7P0guCGVwWSYWSGABIAFhe0XHCkA35KK-XqQRIiuqbRicNDZvkxPdmyPZEF519p-z6mjZKDB0gQcWBBnaHJSDf_n4ePrU07BrBB9P7mYLYR9T62dIto8Bm6v03ZeeyiKb5UV30ySNrs1I5vErfJWYbu0A1LLBNs757eHTKP6ELAM6dkqxKjBBIQ839EB8csU-AjakF3KN75QxoUKkJ1Vg7W8GucK5ICzfnoQ1fO9Fw",
            "types": [
                "local_government_office",
                "police",
                "establishment"
            ],
            "vicinity": "301 Eddy Street, San Francisco"
        ,
        
            "geometry": 
                "location": 
                    "lat": 37.783774,
                    "lng": -122.412944
                
            ,
            "icon": "http://maps.gstatic.com/mapfiles/place_api/icons/police-71.png",
            "id": "0d3efeeecf625bc4c1804081abdd3e0807630f36",
            "name": "San Francisco Police Department",
            "reference": "CoQBfQAAAPgce9xzk7LiKO44_LnwejGGkeoDLgu-OYel8yGwa3qbrGWdoP_XRMsiqnkdIPS6yXkhyAoi-ZXI2gYK3qy2eNqZRqzoH4spVJzkHoyXpZKAaw5pPqpxF90LJ8BIR7BTC8NZ6G0wWvU_ZkpRzBZ4eDGj7jsFJZ4obbHH0TorA2SsEhCxnCiVYI9-YOuTQTjv3WJwGhRIoh9UyZRqx52YQvf8r3F3yCJSKw",
            "types": [
                "local_government_office",
                "police",
                "establishment"
            ],
            "vicinity": "301 eddy st,san francisco,CA 94102"
        ,
        
            "geometry": 
                "location": 
                    "lat": 37.777301,
                    "lng": -122.402107
                
            ,
            "icon": "http://maps.gstatic.com/mapfiles/place_api/icons/police-71.png",
            "id": "522b34dca06a3c1a0bb424065ac5680f02749f26",
            "name": "San Francisco Sheriff's Department",
            "reference": "CoQBgAAAAIuFvo4NygDhwlemYL0aDUeEtU9_XFGOUvTtB5jS1aPoaUudJPjd_ju9leYCs8CbZeje8idACjTKaMqYSnxWFEPWbUnO1XOGS1avoapktXlT9uf-JSIkxEEsEyQswdfMP7cK0Ec69y9-UKnVkW6NwIlw9TtMGuqA4j0DasmGmiGZEhC_ZxRYvT7ZmU51W3aZQqosGhS7EXuLCHbWA-rANQeTUzKAClK7AQ",
            "types": [
                "local_government_office",
                "police",
                "establishment"
            ],
            "vicinity": "70 Oak Grove Street, San Francisco"
        ,
        
            "geometry": 
                "location": 
                    "lat": 37.781357,
                    "lng": -122.417997
                
            ,
            "icon": "http://maps.gstatic.com/mapfiles/place_api/icons/police-71.png",
            "id": "4acea41c3c7ae58298cc1e5b40d5608d0d0dcfd1",
            "name": "Federal Bureau of Investigation",
            "reference": "CoQBfQAAAKNFRxLamyCI4hbWr7juNyrA_ecIuD482GD-axiBBdZgKlvDF5vkJj8SGx__RSjrBinrQsZSj7Obtk8Vml7nPDidxUwT8kDvvY8kri0AFfBXrohe8iISSwohMPk-lBqszK1rD8uhStt4-uucmMNBFZoPOp4MD6oNcGemxwT6haa8EhCsT8jxTbVcWUigjQ2Lb5UnGhSs6eNiPclWCA3sPkDm9ACZZTc70g",
            "types": [
                "local_government_office",
                "police",
                "establishment"
            ],
            "vicinity": "450 Golden Gate Avenue, San Francisco"
        ,
        
            "geometry": 
                "location": 
                    "lat": 37.781249,
                    "lng": -122.417974
                
            ,
            "icon": "http://maps.gstatic.com/mapfiles/place_api/icons/police-71.png",
            "id": "ebe8312c803b968e8f1ff863cca4e2f934ba7872",
            "name": "US Drug Enforcement Administration",
            "reference": "CpQBgQAAAJ6diKHuzZXoj69pGt9EENv10e3nFnKA1C2KtWchDg3P1yYlRztrSTGXQSefiqsEWb5AHO6Qni_Xx9EFV8hWoPUJiuOSsDlBQhHNo6GfKAFzIUDSHWzi0Y154HTsSC8ddGl_h9AadhEJgwlQMNggK_hf5LkU-0jDrXdOee3GszGtrYyH7iVNK77eJyRTV_GjqRIQuiXnREl_U_UaYgLNT-ukwhoUSHpHatll_Jf8-ecjOsfo1SJD1IY",
            "types": [
                "police",
                "establishment"
            ],
            "vicinity": "450 Golden Gate Avenue, San Francisco"
        ,
        
            "geometry": 
                "location": 
                    "lat": 37.781249,
                    "lng": -122.417974
                
            ,
            "icon": "http://maps.gstatic.com/mapfiles/place_api/icons/police-71.png",
            "id": "bb7d9feda3a9287ea0e34b92916efdd53d01b8e4",
            "name": "US Marshals Services",
            "reference": "CoQBcwAAAFZxzSZ_jWYAWo4YBjIGZubm0URiy7JYoSRxrJKwxpIUDv6eT1PbW01Q499iMfBInkG64LWLcs_o2znz-i_W0NDpVJjrdPZnwm-sXG2_2WuJIGYTahn-4ULfLlKUyD6AXQ37TClQxWL1GXEEyzpggTg5TUgdi4OZab98qNK4jJ9kEhARopcjVDPfCl6Dk8UX4BCbGhR-JXlBlKofg8pnJNvn8vO_jB6_zQ",
            "types": [
                "local_government_office",
                "police",
                "establishment"
            ],
            "vicinity": "450 Golden Gate Avenue, San Francisco"
        ,
        
            "geometry": 
                "location": 
                    "lat": 37.781249,
                    "lng": -122.417974
                
            ,
            "icon": "http://maps.gstatic.com/mapfiles/place_api/icons/police-71.png",
            "id": "6bf8854d6ed199b63d7ed9fcea024d0c2f7e5381",
            "name": "US Alcohol Tobacco & Firearms",
            "reference": "CoQBfAAAAPMTmBey9FLuQZhrX6KwhGJFp0U7v_sTcdTX-XUq-pB0Xm7SVRaoUaUd73tszge8b6K06XC_NKjxz0amzAJPSEHAss6biv6y06WGrpRPDxhTKerAX5iNmyfDVAiYNJtwMI9xq7rOwIxzNwgIpHFaORz8MB4reAUkBo6PUc-hKgzbEhBrB9kgeclkDixH9qFQeDOSGhSyz5GT9L2tOnYDfNYX0vZP2rKSwQ",
            "types": [
                "police",
                "establishment"
            ],
            "vicinity": "450 Golden Gate Avenue, San Francisco"
        ,
        
            "geometry": 
                "location": 
                    "lat": 37.775381,
                    "lng": -122.40404
                
            ,
            "icon": "http://maps.gstatic.com/mapfiles/place_api/icons/police-71.png",
            "id": "894232a831a748a606dd084ed84789b38a7fd40b",
            "name": "San Francisco County Jail",
            "reference": "CoQBeAAAADtIDjI7Qs2mK2YbUJPZLGlSMHMJPIPyqF280NdN8bIcBuKofr2ue6_gTMiL5PWuFyRU63wvw8ecyhUoOS-p527Doyu0AiTEWpZNr99RG6eE3RhkSbvOvK-463RGQFxO9HPZAaMrcAX1QMaK6jGPfdJurNGW57J3bXpPRjjPjbeJEhCh_0ua8Njhntw9BTjDQNYIGhTLk95S4p8fccx72y5d3kHK82uJMA",
            "types": [
                "local_government_office",
                "police",
                "establishment"
            ],
            "vicinity": "425 7th Street, San Francisco"
        ,
        
            "geometry": 
                "location": 
                    "lat": 37.775296,
                    "lng": -122.403909
                
            ,
            "icon": "http://maps.gstatic.com/mapfiles/place_api/icons/police-71.png",
            "id": "4ee3bb8e8ffbebf4f06c60ed245074dae7317bb4",
            "name": "San Francisco Police Department; Field Operations",
            "rating": 4.3,
            "reference": "CpQBkAAAAPU3Ykx-3lfEWASNEq9K6G13VcxvU1Dxtp6sKgKEIDoLyCusw8lQiLK1SGZzsY94HswqjiqKTOOpMxU1d1sQi4s8Llcm7cLNyzrYg3ov-Wag-pFC3KijqOtCNjK_982GuYQd6ati-4mwCaKho3h5Ehl7R7bLAU2Y5QlCEKCV1UUBbHxgZINK0fvE2QRV57KB4BIQ-0x6jPSEx2mM4Qn7rUTobxoUrfHFnZnyBWPxOdlIBG9IIV1kKYA",
            "types": [
                "local_government_office",
                "police",
                "establishment"
            ],
            "vicinity": "19th St, San Francisco"
        ,
        
            "geometry": 
                "location": 
                    "lat": 37.775119,
                    "lng": -122.405597
                
            ,
            "icon": "http://maps.gstatic.com/mapfiles/place_api/icons/police-71.png",
            "id": "7c53e354a2ba6a232d546f6a0d4d7035fed2b5d2",
            "name": "CCSF-Sheriffs Department",
            "reference": "CoQBdgAAAFP-c3exZQI0mmXkAlwqFa0FiHzl4zGu-Aaxt3jbfsZEXVCMaeeYeC_RI2WQcqDDwrummRBr-JmsHi3WwOAEjb9DZLI8FAXAaK_Q8_tY-EWmsPz789s6d0jofW3kgMtMswM5DWERCaooTgfP0zHYbo9UvHA6rXnA-UwnHqL37TTIEhBRLJvAFmdVuokrhFXgJG9jGhQhoAkKVWfAe8YTUPHq8PCk7L8eiA",
            "types": [
                "local_government_office",
                "police",
                "establishment"
            ],
            "vicinity": "425 7th Street, San Francisco"
        ,
        
            "geometry": 
                "location": 
                    "lat": 37.775269,
                    "lng": -122.403757
                
            ,
            "icon": "http://maps.gstatic.com/mapfiles/place_api/icons/police-71.png",
            "id": "70201e2b1abd845b00a96fb16f4e7446bcc99375",
            "name": "San Francisco Police Department; Southern Station",
            "reference": "CqQBkQAAAJtzAlqPahtG6mfSBvNKYLoSV9hlduJokTfluyMmX_mGQOv9BC_WEEF3adDHjNq6DpGsIeeQP52euTDd2cG8NenJfCGM3dEgPtNscS5Y85LbGBJ3Xqbh5euWDwYX7gl6EotC8jVtuRrqzzPM3l-zIApsgj1GUCMjnDHYz1kkBRfkVgyxm5IBOYVa6n2i30w8Fw0Pw6CLxavKVeTkMbBdIHwSEKSKTQyGPCnjqiAju7zFfbkaFDV6hvizbtL1YrBDt54JfbzHvpWx",
            "types": [
                "police",
                "establishment"
            ],
            "vicinity": "850 Bryant Street, San Francisco"
        ,
        
            "geometry": 
                "location": 
                    "lat": 37.775269,
                    "lng": -122.403757
                
            ,
            "icon": "http://maps.gstatic.com/mapfiles/place_api/icons/police-71.png",
            "id": "4b803769b50e5870649b334d4c0f73991304b31a",
            "name": "San Francisco Police Department",
            "reference": "CoQBfgAAACsoN0pt2exPTjafsC2G-zFyONXx67Hbp4Xdxw9EvTzhpAXpDwfdaMzdFkh_FqLG3IFvo-Uw2a375fWDsqiLMQTqcppXFUDmsnvtCuPrNsm_BHu_l-Qkm0t7PdiZdTFNhvRtN4-QD1vrVow3K1DM6H759wrYFnOKOzCujCWLnVBsEhBQuHMIBwpVI9axkjQarGHXGhQNfwjLT8NI0o3T8PNUmh8N5llQtw",
            "types": [
                "police",
                "establishment"
            ],
            "vicinity": "850 Bryant Street, San Francisco"
        ,
        
            "geometry": 
                "location": 
                    "lat": 37.775269,
                    "lng": -122.403757
                
            ,
            "icon": "http://maps.gstatic.com/mapfiles/place_api/icons/police-71.png",
            "id": "5f072a25adc29d11a26c3420853f736f798a07a0",
            "name": "Police Commission",
            "reference": "CnRwAAAAlCrhKu-Ht6T9oG0bIiGYxnVYWyscJpBiDAoHxmPzfRxDZzrRlwvmk-VaALjIJfUYcRN4B1KpF6oAvaTJhRq2OPd_cSpE6UnxbrlWEFhIw0XxzYc1B3twF_cU78B4VXDO6CYHy_p8bOgbB06FKhWWexIQJRqT8QnE9_0Tf6AwllOUKBoU9crzscr0ydNhbD4xF_FpAYjuWjc",
            "types": [
                "police",
                "establishment"
            ],
            "vicinity": "850 Bryant Street, San Francisco"
        ,
        
            "geometry": 
                "location": 
                    "lat": 37.775269,
                    "lng": -122.403757
                
            ,
            "icon": "http://maps.gstatic.com/mapfiles/place_api/icons/police-71.png",
            "id": "1ae36e0afe411b1db057af726caa1b721ceacbaf",
            "name": "Police Department-Management Control",
            "reference": "CpQBggAAAOlLL4GfqBVhNG1hV7ufSmV2rv2ucfClR-XCVOWqHggBb9PT7eEjmmnjXqdjoBCy_C8xKsRhTaA9ZpPzD7PsjOZbDfgOMrCPnNL_LkG7ff0tXCtdb-9J32rjLei3R1z2DrYh29ojHHQgDKtxNHkATzamGBP_sELOl-ZiNFse38E80OSae1GIAEGk7qm2IrokIBIQsmlvwPng4fxp1mOof238ZhoUgKRD6wX3XyKWVFhyV0Jaj2liJt8",
            "types": [
                "police",
                "establishment"
            ],
            "vicinity": "850 Bryant Street, San Francisco"
        ,
        
            "geometry": 
                "location": 
                    "lat": 37.775269,
                    "lng": -122.403757
                
            ,
            "icon": "http://maps.gstatic.com/mapfiles/place_api/icons/police-71.png",
            "id": "a41f2aab19f8dcd16d2fa86735ae358884dc653e",
            "name": "San Francisco Police Department; Traffic Enforcment",
            "reference": "CqQBkgAAACqYHg8srBjh7Dm41OwSHWAKZcrJ947wfnat3up6L7UC_rPB2WKErlTbCrbm3E-vNo7TKfZg1eemSsk9B_KbOAb6ig-itLlbhRWUd3ddOpyAfrw3GuWVkkUdOVAGBzNEP9HgxRLNY5DKMFDdiP5QaggqDGZ8EoUNIJHwqUXxKUTr-jBw_lWWK5COMNrrscqgdl9DVIiDfRSRmDEVWe_HzdMSEGZMWvkOvBOEWT1G0hAkZPAaFHdaE3QokGiH68cCw-N1rYQCpP6w",
            "types": [
                "police",
                "establishment"
            ],
            "vicinity": "850 Bryant Street, San Francisco"
        ,
        
            "geometry": 
                "location": 
                    "lat": 37.775269,
                    "lng": -122.403757
                
            ,
            "icon": "http://maps.gstatic.com/mapfiles/place_api/icons/police-71.png",
            "id": "416a6d2815189e3fc6bbb9c9c1ffc2251b602d78",
            "name": "San Francisco Sheriffs Dept; Judicial Division-Bailiffs",
            "reference": "CqQBlwAAANcN9weLjjjijy0auo8lINWJ8UZI1bbSzXnocNs6VB0G742bqhM5B72jgULlPZuAS-olQwBoz3NoiCcT7nBoB0M0SK7jtkLzIZb2sj3sJzU4j9d5guqLvsGrtLT9ZcNs-AhtXFcKP5BEWERCpyN5Vxr9-fxpU8fkuentMnFsAoK_ZthpUvopoSfMTRXe4QYq55zq1yOeLm0ws1ChQff0ydcSELFQ1VpOsge0Vl9dGrpZHqIaFMqT7pAjbrCpAcelDTMBMLqDfsUs",
            "types": [
                "local_government_office",
                "police",
                "establishment"
            ],
            "vicinity": "850 Bryant Street, San Francisco"
        ,
        
            "geometry": 
                "location": 
                    "lat": 37.775252,
                    "lng": -122.403768
                
            ,
            "icon": "http://maps.gstatic.com/mapfiles/place_api/icons/police-71.png",
            "id": "ad648b77d7547f9f125feeb564341c6eee4528d6",
            "name": "San Francisco Police Department Records and Identifcation Bureau",
            "reference": "CqQBnwAAANVBI_eGm1aoTQgMY33tkBXl5UTXKeB1x2rQ8PKyQwP5QyNnmPC4cjtsAS42mX7prStXYAB3tqrg71uxNL0Xsq2dNNKEXmxxRPEGbiYlZUhuRpcplV2Kv_mBEwVO57BYw5hXSqktK903OuETm7GYZrnhaHd6bMUYo_2L6axYbDC2fOCcCHqkr_H4a52imRfTbPJ5T3m1YCqjycgzFRCAoq4SEPk-WQ7feqKvmDm6_NaI1noaFKVCYh6QnwjumS18px6BJhmZWTr1",
            "types": [
                "police",
                "establishment"
            ],
            "vicinity": "850 Bryant Street, San Francisco"
        ,
        
            "geometry": 
                "location": 
                    "lat": 37.775252,
                    "lng": -122.403768
                
            ,
            "icon": "http://maps.gstatic.com/mapfiles/place_api/icons/police-71.png",
            "id": "037d2ff49817265965fe9811a1420b2a25eafae4",
            "name": "Police Department-Investigations Bureau",
            "opening_hours": 
                "open_now": false
            ,
            "reference": "CpQBhQAAAHDVOYEKDEqUGFfHMl_f3ootEmYyQlHQ2LJq8BGxIzV3tGxfEzIXPjVea06EfgynZdXeH-dCqG7I3ENN4We7eSlXGUdi6AWYZixQPPEdd_w0keEdGiiLmFncS86QcIkdyq4cLk3PBtSZFJsPgNKek0lcQAqnFpu_P-4shB8l8lNj9c9noybqA39QE_t0Wj3mlhIQ3Led9nm1rmgUtR2klj0tjxoU07GXuYYOB9_GV6q_I-hHvS365bc",
            "types": [
                "police",
                "establishment"
            ],
            "vicinity": "850 Bryant Street #400, San Francisco"
        
    ],
    "status": "OK"


【讨论】:

你知道从任何 API 获取警察局电话号码吗,请帮忙。 @naser 我们可以在当前位置附近做动态定位吗,或者如果我们搜索任何位置而不是附近的地方,我们如何做到这一点 你有什么办法可以得到附近警察局的电话号码吗? @Reena 没有这样的公共数据库可以提供附近的电话号码。到目前为止,唯一的方法是使用 google places api。但它不会为您提供所有警察局的号码。一些电台已将那里的详细信息上传到谷歌。所以你只能得到那个警察局的信息。 感谢 Naser 的宝贵回复,我已经尝试过 google places api。

以上是关于在android中找到离地理点最近的警察局的主要内容,如果未能解决你的问题,请参考以下文章

快速算法在平面上找到离给定点最近的 x 个点

如何找到距离某个地理点最近的车站和其他 POI?

如何返回离地理位置最近的文件?

Sequelize 地理空间查询:找到距某个位置最近的“n”个点

找到离给定点最近的点

找到离给定点最近的多边形