DownloadPHP Laravel wrapper for the Saudi National Address APIs
Installation
composer require naif/saudiaddress
If your Laravel below 5.5 you need to add service provider and alias to config/app.php Naif\Saudiaddress\SaudiAddressServiceProvider::class,
'SaudiAddress' => Naif\Saudiaddress\Facades\SaudiAddress::class,
API KEYS
Obtain your National Address API key from https://api.address.gov.sa/
Add these to your .env SAUDI_ADDRESS_API_URL=https://apina.address.gov.sa/NationalAddress/v3.1
SAUDI_ADDRESS_API_KEY=XXXXXXXXXXXXXXXXX
Usage
Get a list of regions $regions = SaudiAddress::regions();
Response:
[
0 => {#181
+"Id": "12"
+"Name": " ??????"
}
1 => {#182
+"Id": "13"
+"Name": " ?????"
}
2 => {#188
+"Id": "9"
+"Name": " ?????? ????????"
}
3 => {#189
+"Id": "1"
+"Name": " ??????"
}
]
Get a list of cities within a region (by region id)
* To get a list of all cities don't pass a region id $cities = SaudiAddress::cities(1);
Response:
[
0 => {#183
+"Id": "3"
+"Name": "??????"
}
1 => {#189
+"Id": "1061"
+"Name": "?????"
}
2 => {#190
+"Id": "828"
+"Name": "???????"
}
3 => {#191
+"Id": "669"
+"Name": "????????"
}
]
Get a list of districts within a city (by city id)
$districts = SaudiAddress::districts(1);
Response:
[
0 => {#184
+"Id": "10700001041"
+"Name": "????? ??? ????? ?????"
}
1 => {#190
+"Id": "10700001018"
+"Name": "?? ??? ????"
}
2 => {#191
+"Id": "10700001021"
+"Name": "?? ????????"
}
3 => {#192
+"Id": "10700001030"
+"Name": "?? ????????"
}
4 => {#193
+"Id": "10700001044"
+"Name": "?? ???????"
}
5 => {#194
+"Id": "10700001012"
+"Name": "?? ??????"
}
]
Geocode, to get address details by geo location (latitude,longitude) $address = SaudiAddress::geoCode(24.774265,46.738586);
Response:
[
+"Title": null
+"Address1": "7596 ??????? - Al Hamra Dist.,?? ???????"
+"Address2": "RIYADH,?????? 13216 - 2802"
+"ObjLatLng": "1"
+"BuildingNumber": "7596"
+"Street": "???????"
+"District": "Al Hamra Dist.,?? ???????"
+"City": "RIYADH,??????"
+"PostCode": "13216"
+"AdditionalNumber": "2802"
+"RegionName": "????? ??????"
+"PolygonString": null
+"IsPrimaryAddress": null
+"UnitNumber": null
+"Latitude": null
+"Longitude": null
+"CityId": "3"
+"RegionId": null
+"Restriction": "Null"
+"PKAddressID": null
+"DistrictID": null
+"Title_L2": null
+"RegionName_L2": null
+"City_L2": null
+"Street_L2": null
+"District_L2": null
+"CompanyName_L2": null
+"GovernorateID": null
+"Governorate": null
+"Governorate_L2": null
]
Verify an address by (Bulding No, PostCode, Additional No) $verify = SaudiAddress::verify(7596,13216,2802);
Response:
true/false
To get results in English, just pass 'E' as a last paramater.
Example $districts = SaudiAddress::districts(1,'E');
Support:
naif@naif.io
https://www.linkedin.com/in/naif
License
The MIT License (MIT). Please see License File for more information.
|