You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
2.3 KiB
2.3 KiB
LINGYUN.Abp.Location
Introduction
LINGYUN.Abp.Location is a location service foundation module that provides geographic location-related functionality, including geocoding (forward/reverse), distance calculation, and more.
Features
- Geocoding and Reverse Geocoding
- Location distance calculation (based on Google algorithm, error <0.2m)
- Location offset calculation
- Support for POI (Points of Interest) and road information
- Extensible location resolution providers
Installation
dotnet add package LINGYUN.Abp.Location
Usage
- Add
[DependsOn(typeof(AbpLocationModule))]to your module class.
[DependsOn(typeof(AbpLocationModule))]
public class YourModule : AbpModule
{
// ...
}
- Inject and use the location resolution service:
public class YourLocationService
{
private readonly ILocationResolveProvider _locationProvider;
public YourLocationService(ILocationResolveProvider locationProvider)
{
_locationProvider = locationProvider;
}
public async Task<GecodeLocation> GeocodeAsync(string address)
{
return await _locationProvider.GeocodeAsync(address);
}
public async Task<ReGeocodeLocation> ReGeocodeAsync(double lat, double lng)
{
return await _locationProvider.ReGeocodeAsync(lat, lng);
}
}
Advanced Usage
1. Distance Calculation
// Calculate distance between two locations
var location1 = new Location { Latitude = 39.9042, Longitude = 116.4074 }; // Beijing
var location2 = new Location { Latitude = 31.2304, Longitude = 121.4737 }; // Shanghai
double distance = Location.CalcDistance(location1, location2); // Returns distance in meters
2. Calculate Location Offset Range
var location = new Location { Latitude = 39.9042, Longitude = 116.4074 };
// Calculate offset range for specified distance (meters)
var position = Location.CalcOffsetDistance(location, 1000); // 1km range
3. Custom Location Resolution Provider
public class CustomLocationProvider : ILocationResolveProvider
{
public async Task<GecodeLocation> GeocodeAsync(string address)
{
// Implement geocoding logic
}
public async Task<ReGeocodeLocation> ReGeocodeAsync(double lat, double lng)
{
// Implement reverse geocoding logic
}
}