我创建了一个脚本来获取lat和long
的位置$lat = '51.52682970000001';
$long = '-0.09787470000003395';
$url = 'http://api.postcodes.io/postcodes?lon='.$long.'&lat='.$lat;
echo $get_live_data = file_get_contents($url);
echo "<pre>";
echo "<script>console.log(".$get_live_data.");</script>";
print_r($get_live_data);
返回此格式中的数据
{
"status": 200,
"result": [
{
"postcode": "EC1V 3AR",
"quality": 1,
"eastings": 532081,
"northings": 182577,
"country": "England",
"nhs_ha": "London",
"longitude": -0.0974238437520936,
"latitude": 51.5266670984233,
"parliamentary_constituency": "Islington South and Finsbury",
"european_electoral_region": "London",
"primary_care_trust": "Islington",
"region": "London",
"lsoa": "Islington 023C",
"msoa": "Islington 023",
"nuts": "Bunhill",
"incode": "3AR",
"outcode": "EC1V",
"distance": 36.142779048,
"admin_district": "Islington",
"parish": "Islington, unparished area",
"admin_county": null,
"admin_ward": "Bunhill",
"ccg": "NHS Islington",
"codes": {
"admin_district": "E09000019",
"admin_county": "E99999999",
"admin_ward": "E05000367",
"parish": "E43000209",
"ccg": "E38000088"
}
},
{
"postcode": "EC1V 3AT",
"quality": 5,
"eastings": 532081,
"northings": 182577,
"country": "England",
"nhs_ha": "London",
"longitude": -0.0974238437520936,
"latitude": 51.5266670984233,
"parliamentary_constituency": "Islington South and Finsbury",
"european_electoral_region": "London",
"primary_care_trust": "Islington",
"region": "London",
"lsoa": "Islington 023C",
"msoa": "Islington 023",
"nuts": "Bunhill",
"incode": "3AT",
"outcode": "EC1V",
"distance": 36.142779048,
"admin_district": "Islington",
"parish": "Islington, unparished area",
"admin_county": null,
"admin_ward": "Bunhill",
"ccg": "NHS Islington",
"codes": {
"admin_district": "E09000019",
"admin_county": "E99999999",
"admin_ward": "E05000367",
"parish": "E43000209",
"ccg": "E38000088"
}
},
{
"postcode": "EC1V 8AZ",
"quality": 1,
"eastings": 532081,
"northings": 182577,
"country": "England",
"nhs_ha": "London",
"longitude": -0.0974238437520936,
"latitude": 51.5266670984233,
"parliamentary_constituency": "Islington South and Finsbury",
"european_electoral_region": "London",
"primary_care_trust": "Islington",
"region": "London",
"lsoa": "Islington 023C",
"msoa": "Islington 023",
"nuts": "Bunhill",
"incode": "8AZ",
"outcode": "EC1V",
"distance": 36.142779048,
"admin_district": "Islington",
"parish": "Islington, unparished area",
"admin_county": null,
"admin_ward": "Bunhill",
"ccg": "NHS Islington",
"codes": {
"admin_district": "E09000019",
"admin_county": "E99999999",
"admin_ward": "E05000367",
"parish": "E43000209",
"ccg": "E38000088"
}
},
{
"postcode": "EC1V 8BJ",
"quality": 1,
"eastings": 532081,
"northings": 182577,
"country": "England",
"nhs_ha": "London",
"longitude": -0.0974238437520936,
"latitude": 51.5266670984233,
"parliamentary_constituency": "Islington South and Finsbury",
"european_electoral_region": "London",
"primary_care_trust": "Islington",
"region": "London",
"lsoa": "Islington 023C",
"msoa": "Islington 023",
"nuts": "Bunhill",
"incode": "8BJ",
"outcode": "EC1V",
"distance": 36.142779048,
"admin_district": "Islington",
"parish": "Islington, unparished area",
"admin_county": null,
"admin_ward": "Bunhill",
"ccg": "NHS Islington",
"codes": {
"admin_district": "E09000019",
"admin_county": "E99999999",
"admin_ward": "E05000367",
"parish": "E43000209",
"ccg": "E38000088"
}
},
{
"postcode": "EC1V 8BU",
"quality": 1,
"eastings": 532081,
"northings": 182577,
"country": "England",
"nhs_ha": "London",
"longitude": -0.0974238437520936,
"latitude": 51.5266670984233,
"parliamentary_constituency": "Islington South and Finsbury",
"european_electoral_region": "London",
"primary_care_trust": "Islington",
"region": "London",
"lsoa": "Islington 023C",
"msoa": "Islington 023",
"nuts": "Bunhill",
"incode": "8BU",
"outcode": "EC1V",
"distance": 36.142779048,
"admin_district": "Islington",
"parish": "Islington, unparished area",
"admin_county": null,
"admin_ward": "Bunhill",
"ccg": "NHS Islington",
"codes": {
"admin_district": "E09000019",
"admin_county": "E99999999",
"admin_ward": "E05000367",
"parish": "E43000209",
"ccg": "E38000088"
}
},
{
"postcode": "EC1V 8BY",
"quality": 1,
"eastings": 532062,
"northings": 182635,
"country": "England",
"nhs_ha": "London",
"longitude": -0.097675844728179,
"latitude": 51.5271927531582,
"parliamentary_constituency": "Islington South and Finsbury",
"european_electoral_region": "London",
"primary_care_trust": "Islington",
"region": "London",
"lsoa": "Islington 023B",
"msoa": "Islington 023",
"nuts": "Bunhill",
"incode": "8BY",
"outcode": "EC1V",
"distance": 42.685151811,
"admin_district": "Islington",
"parish": "Islington, unparished area",
"admin_county": null,
"admin_ward": "Bunhill",
"ccg": "NHS Islington",
"codes": {
"admin_district": "E09000019",
"admin_county": "E99999999",
"admin_ward": "E05000367",
"parish": "E43000209",
"ccg": "E38000088"
}
},
{
"postcode": "EC1V 3PA",
"quality": 1,
"eastings": 532052,
"northings": 182547,
"country": "England",
"nhs_ha": "London",
"longitude": -0.0978528715183008,
"latitude": 51.5264042809863,
"parliamentary_constituency": "Islington South and Finsbury",
"european_electoral_region": "London",
"primary_care_trust": "Islington",
"region": "London",
"lsoa": "Islington 023C",
"msoa": "Islington 023",
"nuts": "Bunhill",
"incode": "3PA",
"outcode": "EC1V",
"distance": 47.355650701,
"admin_district": "Islington",
"parish": "Islington, unparished area",
"admin_county": null,
"admin_ward": "Bunhill",
"ccg": "NHS Islington",
"codes": {
"admin_district": "E09000019",
"admin_county": "E99999999",
"admin_ward": "E05000367",
"parish": "E43000209",
"ccg": "E38000088"
}
},
{
"postcode": "EC1V 3PD",
"quality": 1,
"eastings": 532045,
"northings": 182544,
"country": "England",
"nhs_ha": "London",
"longitude": -0.0979548407904613,
"latitude": 51.5263789570549,
"parliamentary_constituency": "Islington South and Finsbury",
"european_electoral_region": "London",
"primary_care_trust": "Islington",
"region": "London",
"lsoa": "Islington 023C",
"msoa": "Islington 023",
"nuts": "Bunhill",
"incode": "3PD",
"outcode": "EC1V",
"distance": 50.456384882,
"admin_district": "Islington",
"parish": "Islington, unparished area",
"admin_county": null,
"admin_ward": "Bunhill",
"ccg": "NHS Islington",
"codes": {
"admin_district": "E09000019",
"admin_county": "E99999999",
"admin_ward": "E05000367",
"parish": "E43000209",
"ccg": "E38000088"
}
},
{
"postcode": "EC1V 3RG",
"quality": 5,
"eastings": 532099,
"northings": 182579,
"country": "England",
"nhs_ha": "London",
"longitude": -0.0971637753764948,
"latitude": 51.5266808645084,
"parliamentary_constituency": "Islington South and Finsbury",
"european_electoral_region": "London",
"primary_care_trust": "Islington",
"region": "London",
"lsoa": "Islington 023C",
"msoa": "Islington 023",
"nuts": "Bunhill",
"incode": "3RG",
"outcode": "EC1V",
"distance": 52.042781777,
"admin_district": "Islington",
"parish": "Islington, unparished area",
"admin_county": null,
"admin_ward": "Bunhill",
"ccg": "NHS Islington",
"codes": {
"admin_district": "E09000019",
"admin_county": "E99999999",
"admin_ward": "E05000367",
"parish": "E43000209",
"ccg": "E38000088"
}
},
{
"postcode": "EC1V 3QX",
"quality": 1,
"eastings": 531990,
"northings": 182575,
"country": "England",
"nhs_ha": "London",
"longitude": -0.0987355952757765,
"latitude": 51.5266703846037,
"parliamentary_constituency": "Islington South and Finsbury",
"european_electoral_region": "London",
"primary_care_trust": "Islington",
"region": "London",
"lsoa": "Islington 023C",
"msoa": "Islington 023",
"nuts": "Bunhill",
"incode": "3QX",
"outcode": "EC1V",
"distance": 62.319878004,
"admin_district": "Islington",
"parish": "Islington, unparished area",
"admin_county": null,
"admin_ward": "Bunhill",
"ccg": "NHS Islington",
"codes": {
"admin_district": "E09000019",
"admin_county": "E99999999",
"admin_ward": "E05000367",
"parish": "E43000209",
"ccg": "E38000088"
}
}
]
}
现在我需要在变量中获取邮政编码, $ postcode1 = EC1V 3AR, $ postcode2 = EC1V XVG 等等..