Anantika.KodePosIndonesia
1.0.0
dotnet add package Anantika.KodePosIndonesia --version 1.0.0
NuGet\Install-Package Anantika.KodePosIndonesia -Version 1.0.0
<PackageReference Include="Anantika.KodePosIndonesia" Version="1.0.0" />
paket add Anantika.KodePosIndonesia --version 1.0.0
#r "nuget: Anantika.KodePosIndonesia, 1.0.0"
// Install Anantika.KodePosIndonesia as a Cake Addin #addin nuget:?package=Anantika.KodePosIndonesia&version=1.0.0 // Install Anantika.KodePosIndonesia as a Cake Tool #tool nuget:?package=Anantika.KodePosIndonesia&version=1.0.0
KodePosIndonesia
General information
This is a library that provides the list of Province (Propinsi), City (Kota/Kabupaten), District (Kecamatan), SubDistrict (Kelurahan/Desa) and its Postal Code. Initially, I wrote it to assist many of my personal project. This library points to my free plan Firebase Realtime Database, hence need an internet connection. Since I made this in my free time only, further development may be uncertain.
Disclaimer
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
How to Use
Instancing
There are 2 ways of instancing the unit of work. You can choose the one that suit your need.
Using dependency injection (recommended)
- Register the interface and concrete class as a service
using KodePosIndonesia; // bunch of codes here builder.Services.AddScoped<IKodePos, KodePos>();
- Resolve the injected interface, The way to resolve depends on what framework you are working. You might need to modify the code below accordingly. This example below is for Blazor .Net 6 project.
using KodePosIndonesia; // bunch of codes here @inject IKodePos kodePos;
Using a
using
statement// import namespace using KodePosIndonesia; // bunch of codes here // instancing KodePos object using KodePos kodePos = new(); // using API. See the section below. // or if you're using older version of .Net // instancing KodePos object. using (KodePos kodePos = new KodePos()) { // using API. See the section below. }
Using the API
Your application should provides the mechanism for user to select a model and then store it to a field or property. in this example, I will use these fields to store user selected model.
private ProvinceModel selectedProvince;
private CityModel selectedCity;
private DistrictModel selectedDistrict;
private SubDistrictModel selectedSubDistrict;
Get all provinces.
IEnumerable<ProvinceModel> provinceList = await kodePos.ProvinceRepository.GetAsync();
After you get the province list, you should execute the user selecting mechanism and store it to a field.
Get the Cities based on selected province.
IEnumerable<CityModel> cityList = await kodePos.CityRepository.GetAsync(selectedProvince.Id);
Get the Districts based on selected city.
IEnumerable<DistrictModel> districtList = await kodePos.DistrictRepository.GetAsync(selectedCity.Id);
Get the SubDistricts based on selected district.
IEnumerable<SubDistrictModel> subDistrictList = await kodePos.SubDistrictRepository.GetAsync(selectedDistrict.Id);
You can find the 5 digit Indonesian postal code in SubDistrictModel. Here are the properties.
public class SubDistrictModel : BaseModel
{
public int Id { get; set; }
public string Name { get; set; }
public int PostalCode { get; set; }
public int DistrictId { get; set; }
}
Find the SubDistrict based on PostalCode
Sometime, you need to provide a mechanism for user to search an address based on its postal code. Here is how to do it.
//set the index
kodePos.SubDistrictRepository.IndexOn = SubDistrictIndex.PostalCode.ToString();
int postalCode = 12520;
IEnumerable<SubDistrictModel> subDistrictList = await kodePos.SubDistrictRepository.GetAsync(postalCode);
// [optional] you need to revert the index back only if you want to search based on DistrictId.
kodePos.SubDistrictRepository.IndexOn = SubDistrictIndex.DistrictId.ToString();
Get the complete address
This library provides the AddressModel that defines all needed property.
public class AddressModel : BaseModel
{
public SubDistrictModel SubDistrict { get; set; }
public DistrictModel District { get; set; }
public CityModel City { get; set; }
public ProvinceModel Province { get; set; }
}
You get the model by executing the SubDistrictModel extension.
using KodePosIndonesia.Extensions;
AddressModel address = await selectedSubDistrict.GetCompleteAddress();
This process is expensive and should be used only when you don't have its parent model. If you do, you should create the object yourself.
AddressModel address = new AddressModel()
{
SubDistrict = selectedSubDistrict,
District = selectedDistrict,
City = selectedCity,
Province = selectedProvince
}
Credit
Thanks to Edwin for providing the SQL data. You can visit his repository in this link. I have transformed the data to suit my class and have cleaned the data for duplicates. | Record | Count | |----------------|-----------| | Province | 34 | | City | 475 | | District | 6,994 | | SubDistrict | 81,225 |
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.Extensions.Http (>= 7.0.0)
- Newtonsoft.Json (>= 13.0.3)
- System.Linq (>= 4.3.0)
- System.Linq.Async (>= 6.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0 | 186 | 5/9/2023 |