NewLife.Map 2.8.2026.1024

dotnet add package NewLife.Map --version 2.8.2026.1024
                    
NuGet\Install-Package NewLife.Map -Version 2.8.2026.1024
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NewLife.Map" Version="2.8.2026.1024" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NewLife.Map" Version="2.8.2026.1024" />
                    
Directory.Packages.props
<PackageReference Include="NewLife.Map" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add NewLife.Map --version 2.8.2026.1024
                    
#r "nuget: NewLife.Map, 2.8.2026.1024"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package NewLife.Map@2.8.2026.1024
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=NewLife.Map&version=2.8.2026.1024
                    
Install as a Cake Addin
#tool nuget:?package=NewLife.Map&version=2.8.2026.1024
                    
Install as a Cake Tool

NewLife.Map - Unified Map Component Library

GitHub top language

GitHub License NuGet Downloads NuGet NuGet prerelease test locales platform arch contributors

🌐 简体中文 | 繁體中文 | Español | Deutsch | 日本語 | Français | Português | Русский | 한국어 | العربية

A map component library that unifies Baidu, AMap, Tencent, Tianditu and the enterprise map API platform behind a single interface. It hides vendor differences and provides geocoding, reverse geocoding, distance calculation, coordinate conversion and multi-key circuit breaking.

Source: https://github.com/NewLifeX/NewLife.Map
NuGet: NewLife.Map

Repository layout

Project Role Description
NewLife.Map Map component library (NuGet package) Unified IMap interface + multi-vendor adapters + coordinate conversion + key circuit breaking
MapApi Enterprise map API platform (web service) Multi-vendor aggregation + multi-level GeoHash cache + Cube admin backend
XUnitTest Unit tests Geocoding / reverse geocoding / distance / coordinate conversion tests for each provider (real-service integration cases are skipped by default)

Documentation

  • Requirements — vision, core goals, functional requirements, deferred list
  • Feature list — module/feature codes with three-dimensional status tracking (implementation/test/comments)
  • Architecture — layering, components, key flows and design decisions
  • Competitive analysis — comparison matrix and gap analysis versus Geocoding.net / ProjNET / domestic single-vendor wrappers

Features

  • Unified IMap interface that hides the differences between Baidu / AMap / Tencent / Tianditu / enterprise self-hosted (NewLifeMap); switching vendors requires zero code changes
  • Geocoding (address → coordinates) / reverse geocoding (coordinates → address), automatically merging POI semantic information to complete address components
  • Route distance / driving time, with vendor-specific strategy parameters abstracted away
  • Administrative division queries (AMap / Tencent), POI / region search (Baidu / Tianditu), IP location (Baidu / Tencent / platform online resolution)
  • Coordinate system conversion: built-in offline formulas for WGS84 / GCJ02 / BD09 + vendor online batch conversion (Baidu's special from/to mapping is encapsulated)
  • Multi-key rotation with automatic circuit breaking + scheduled recovery; a single key being rate-limited or banned does not affect overall availability
  • Token-bucket rate limiting via MaxQps and request statistics (total / success rate / average latency), preventing a single key from being banned by high-frequency requests
  • Optional exception throwing via ThrowException, making unified handling easier for upper layers
  • Multiple target frameworks: net45 / net461 / netstandard2.0 / netstandard2.1 (compatible with legacy projects and modern .NET)
  • Strong-name signed, suitable for reflection and plugin systems
  • Built-in runtime localization: 11 languages with English as the source and fallback; exception messages, logs and assembly metadata are translated through compile-time locale tables
  • Stardust registry integration: the NewLifeMap provider discovers server addresses automatically, enabling seamless switching across multiple instances / blue-green deployments

Installation

# Stable
dotnet add package NewLife.Map
# Preview (date-based)
dotnet add package NewLife.Map --prerelease

Quick start

using NewLife.Map;
using NewLife.Data;

// Choose a concrete map provider (BaiduMap / AMap / WeMap / TianDiTu / NewLifeMap)
var map = new BaiduMap { AppKey = "<BAIDU_AK>" }; // Separate multiple keys with commas

// 1. Forward geocoding: address -> coordinates
var geo = await map.GetGeoAsync("北京市海淀区上地十街10号", city: "北京", coordtype: "bd09ll", formatAddress: true);
Console.WriteLine($"Point: {geo?.Location}  Semantic: {geo?.Title}");

// 2. Reverse geocoding: coordinates -> address
var addr = await map.GetReverseGeoAsync(new GeoPoint(116.30815, 40.056885), "bd09ll");
Console.WriteLine(addr?.Address);

// 3. Distance (driving)
var d = await map.GetDistanceAsync(new GeoPoint(116.30815, 40.056885), new GeoPoint(116.39745, 39.909187), "bd09ll");
Console.WriteLine($"Distance={d?.Distance}m Duration={d?.Duration}s");

// 4. Coordinate conversion (offline formulas)
var list = await map.ConvertAsync(new List<GeoPoint> { new(116.30815, 40.056885) }, from: "wgs84", to: "bd09");
Console.WriteLine(list[0]);

Coordinates must use spherical coordinates (longitude/latitude); the output is a point in the BD09 coordinate system.

Create dynamically through the factory

var m1 = Map.Create("Baidu");           // Automatically matches the *Map suffix
var m2 = Map.Create("AMap");            // AMap
var m3 = Map.Create("NewLifeMap");

// Or create by enum
var m4 = MapFactory.Create(MapKinds.TianDiTu);

AppKey is set after instantiation; multiple keys are separated by commas and rotated internally.

Map providers

Provider Class Main capabilities Notes
Baidu Maps BaiduMap Geocoding / reverse geocoding / distance / POI search / IP location / coordinate conversion (online + offline) KeyName=ak
AMap AMap Geocoding / reverse geocoding / distance / administrative divisions KeyName=key
Tencent Maps WeMap Geocoding / reverse geocoding / distance / IP location / administrative divisions KeyName=key
Tianditu TianDiTu Geocoding / reverse geocoding / distance (with waypoints) / POI search KeyName=tk
OSM/Nominatim NominatimMap Geocoding / reverse geocoding (open source, free, no key, WGS84) No key required
NewLife Map Platform NewLifeMap Enterprise aggregation API (connects to the MapApi platform) Service discovery via Stardust

To add a provider, see "Steps to extend a new map provider" below and follow the AMap/BaiduMap pattern.

Coordinate system conversion

Name Description Common vendors
WGS84 International GPS standard Raw device positioning
GCJ02 Offset applied by the State Bureau of Surveying and Mapping AMap / Tencent / most Chinese online maps
BD09 Baidu offset Baidu
// Offline formula conversion, no vendor quota consumed
var p = await map.ConvertAsync(new GeoPoint(lng, lat), from: "wgs84", to: "gcj02");

// Baidu online batch conversion, from/to index values already encapsulated
var list = await map.ConvertAsync(points, from: "wgs84ll", to: "bd09ll");

AppKey multi-key rotation and circuit breaking

  • Pass AppKey="k1,k2,k3"; each request increments an index and takes the remainder for rotation
  • When a response matches invalid keywords (such as TOO_FREQUENT / LIMIT / INVALID), RemoveKey() is called to take that key offline temporarily
  • Offline keys enter _pendingKeys and are scanned by a TimerX timer, then restored automatically when due
  • Recovery time policy: currently passed in by the caller (for example, 1 hour)

NewLifeMap aggregation platform

NewLifeMap points to the built-in MapApi enterprise map API platform. The platform aggregates multiple vendors and caches results, so clients do not need to be aware of the underlying differences.

// Option 1: specify the server directly
var map = new NewLifeMap("http://mapapi.company.local") { AppKey = "<KEY>" };

// Option 2: dependency injection + Stardust Registry automatic address resolution
services.AddSingleton<IMap, NewLifeMap>();
// The NewLifeMap(IServiceProvider) constructor tries: IRegistry -> StarFactory
  • The bound ApiHttpClient automatically updates the server address list, enabling seamless switching during MapApi multi-replica / blue-green deployments
  • The platform exposes unified GET /Map/Geo, /Map/ReverseGeo (reverse geocoding), /Map/GeoAddress (forward geocoding) and /Map/Distance (distance) endpoints; a four-level GeoHash cache (6–9 characters) reduces vendor calls

Error handling

  • Default: a non-success response does not throw; the method returns null
  • With map.ThrowException = true;, an Exception is thrown for unified capture in the outer layer
  • Debug information for the most recent request: LastUrl / LastString / LastResult / LastKey

API overview

Task<GeoAddress?> GetGeoAsync(string address, string? city=null, string? coordtype=null, bool formatAddress=false);
Task<GeoAddress?> GetReverseGeoAsync(GeoPoint point, string? coordtype);
Task<Driving?>    GetDistanceAsync(GeoPoint origin, GeoPoint destination, string? coordtype, int type=0);
Task<IList<GeoPoint>> ConvertAsync(IList<GeoPoint> points, string from, string to);

Extensions (provider-specific):

Task<GeoAddress?> PlaceSearchAsync(...);      // BaiduMap / TianDiTu POI / region search
Task<IList<GeoArea>> GetAreaAsync(...);       // AMap administrative divisions
Task<IDictionary<string, object?>> IpLocationAsync(...); // BaiduMap / WeMap IP location

Extending a new map provider

  1. Create a class XXXMap : Map, IMap
  2. Set Server / KeyName
  3. Override InvokeAsync<T> to parse the vendor's unified response structure & error codes
  4. Implement GetGeoAsync / GetReverseGeoAsync / other required capabilities
  5. If there are vendor-specific rate-limiting / invalidation signals, override IsValidKey to return true and trigger temporary offline
  6. Register in the MapFactory static constructor with Register<XXXMap>(MapKinds.XXX)
  7. Submit unit tests covering the main functionality and edge cases

Unit tests

The repository contains the XUnitTest project; the solution is NewLife.Map.slnx (VS 2026 / .NET 10 new XML format):

  • By default it runs deterministic tests: 84 cases; a local HTTP stub service covers URL construction and response parsing for each vendor; execution takes about 0.4–1 second and runs reliably on all RIDs (including CI)
  • Real vendor / OSM / platform online tests are marked Category=Integration and skipped by default via IntegrationFact; "Run All" in the VS Test Explorer behaves the same as dotnet test
  • To enable integration tests: first set the environment variable NEWLIFE_MAP_INTEGRATION=1, then run with --filter "Category=Integration"
  • Keep real keys in local user secrets or environment variables; never commit them to the repository

Run (Windows PowerShell):

dotnet test -c Release
$env:NEWLIFE_MAP_INTEGRATION = 1
dotnet test -c Release --filter "Category=Integration"   # Optional: live-environment integration

Build

dotnet build -c Release

The output (multi-framework build) is located in Bin/.

Compatibility testing (CI)

Triggered on push / PR, covering mainstream RIDs:

  • Unit test matrix: win-x64 / linux-x64 / linux-arm64 / linux-la64 (LoongArch, QEMU emulation + Loongson .NET SDK, see test.yml)
  • NativeAOT smoke matrix: the same four RIDs (AotSmoke project, 18 scenarios), see aot.yml

Roadmap / TODO

All completed on 2026-08-04: concurrent rate limiting (MAP-12), failure metrics (MAP-13), benchmark comparison (MAP-14)

Versioning

Major version = compatibility changes; minor version = new features; revision = fixes / optimizations. VersionSuffix carries a date for easy build identification.

Contributing

Issues / PRs are welcome: bugs, performance optimizations, support for more maps, documentation and tests. Before submitting, please read .github/copilot-instructions.md to keep the code style consistent.

License

MIT; keep the copyright notice and you are free to use it in commercial / open-source projects.


Ecosystem Map

NewLife is a layered ecosystem of independently versioned open-source projects. The map below is shared verbatim by every NewLife repository; each project links to its repository and its primary NuGet package.

Project What it does Downloads
Foundation
NewLife.Core Logging, configuration, caching, networking, serialization, scheduling and APM tracing. NuGet
NewLife.XCode Data middleware: single tables at the tens-of-billions scale, automatic sharding, read-write splitting, 10+ databases. NuGet
NewLife.Net High-performance network library: 1.77M pps / 14.5 Gbps on a single machine (TCP 1KB, 2026-10), 4M long-lived TCP connections. NuGet
NewLife.Remoting Protocol communication and RPC framework for client/server applications and IoT devices. NuGet
NewLife.Agent Installs .NET applications as OS daemons: Windows services and Linux systemd. NuGet
NewLife.Templates dotnet new project templates for console, web, API, service, data and IoT projects. NuGet
Data & Messaging
NewLife.Redis Redis client with microsecond latency, millions of ops/s and built-in message queues. NuGet
NewLife.RocketMQ Pure managed RocketMQ client for Apache RocketMQ and Alibaba Cloud Message Queue. NuGet
NewLife.MQTT MQTT client and server, including Alibaba Cloud IoT connectivity. NuGet
NewLife.NovaDb Hybrid database in C#: embedded or networked, relational, time-series, message queue and KV in one. NuGet
NewLife.MySql MySql driver and helper layer built on the NewLife data stack. NuGet
Web, AI & Distributed
NewLife.Cube Rapid admin-platform framework: permissions, SSO, OAuth server and CRUD scaffolding. NuGet
Stardust Distributed service platform: node management, APM, configuration center, registry and release center. NuGet
AntJob Distributed task and real-time data scheduling platform with sharding, retries and backfill. NuGet
NewLife.AI Unified client for 46 LLM providers plus ChatAI, a ready-to-run web chat application. NuGet
Industrial & IoT
NewLife.IoT IoT standard library defining protocol contracts and device abstractions. NuGet
NewLife.Modbus Modbus TCP/RTU/ASCII implementation on top of NewLife.IoT. NuGet
NewLife.Siemens Siemens PLC protocol on top of NewLife.IoT. NuGet
NewLife.Omron Omron PLC protocol on top of NewLife.IoT. NuGet
NewLife.Melsec Mitsubishi Melsec PLC protocol on top of NewLife.IoT. NuGet
NewLife.OPC OPC client for industrial data access. —
NewLife.BACnet BACnet building-automation protocol stack. NuGet
ZeroIoT Lightweight open-source IoT platform with gateway and device management. —
Vehicle Telematics
NewLife.JT808 JT/T 808 vehicle positioning protocol: 70+ message bodies, 2011/2013/2019. NuGet
NewLife.JT809 JT/T 809 platform-to-platform protocol for transport authorities. NuGet
NewLife.JT1078 JT/T 1078 in-vehicle video: RTP parsing, FLV/fMP4 remuxing and live streaming. NuGet
Domain Components
NewLife.Office One package for Excel, Word, PPT, PDF and 15+ document formats. NuGet
NewLife.Audio Cross-platform audio: codecs, device I/O, DSP, containers and streaming. NuGet
NewLife.Video Video codecs, container formats, frame processing and streaming. NuGet
NewLife.Map Unified interface over Baidu, AMap, Tencent and Tianditu with geocoding and coordinate conversion. NuGet
NewLife.IP IPv4 geolocation with an offline memory-mapped database and an online API fallback. NuGet
Tools & Products
CrazyCoder Developer toolbox: network, serial port, crypto, regex, Modbus and MQTT. NuGet
GitCandy Self-hosted Git source code management system. —
LuckyClover Installs the matching .NET runtime automatically when launched from an older host. —

Badges show the primary package of each project; theme, extension and satellite packages are listed on their NuGet pages.The 30+ packages not listed here (FTP, LoRa, Office extensions, protocol drivers and more) are available under the NewLifeX organization and on newlifex.com.

Team

<img src="https://newlifex.com/logo.png" width="48" align="right" alt="NewLife" />

Founded in 2002, the NewLife team has spent more than two decades on the .NET and IoT ecosystem, maintains nearly 100 open-source projects (34 of them core to this map), and delivers integrated software and hardware solutions for power, logistics, healthcare, industrial control and internet industries. We live by the motto "learning has no seniority — mastery earns respect".

Open-source components have been downloaded 6.48M times from NuGet (ecosystem-wide, as of 2026-10).

Website: https://newlifex.com · Open source organization: https://github.com/NewLifeX

<details> <summary>WeChat Official Account: 智能大石头 (scan to follow)</summary>

智能大石头

</details>

Product 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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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 is compatible. 
.NET Framework net45 is compatible.  net451 was computed.  net452 was computed.  net46 was computed.  net461 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on NewLife.Map:

Repository Stars
NewLifeX/XCoder
新生命码神工具,代码生成、网络工具、API工具、串口工具、正则工具、图标工具、加解密工具、地图接口。
Version Downloads Last Updated
2.8.2026.1024 101 10/24/2026
2.8.2026.1024-beta0337 94 10/24/2026
2.7.2026.1022-beta0123 87 10/22/2026
2.7.2026.1019-beta1206 90 10/19/2026
2.7.2026.1019-beta0438 91 10/19/2026
2.7.2026.1018-beta1723 98 10/18/2026
2.7.2026.1017-beta1410 116 10/17/2026
2.7.2026.1017-beta0928 91 10/17/2026
2.7.2026.804 151 8/4/2026
2.7.2026.804-beta1128 127 8/4/2026
2.6.2026.304-beta0614 171 3/4/2026
2.6.2026.302-beta0610 136 3/2/2026
2.6.2026.301-beta0614 137 3/1/2026
2.6.2026.211-beta0610 147 2/11/2026
2.6.2026.206-beta1254 147 2/6/2026
2.6.2026.114-beta0612 152 1/14/2026
2.6.2026.102 298 1/2/2026
2.6.2026.102-beta1626 144 1/2/2026
2.6.2025.1113-beta0606 350 11/13/2025
2.6.2025.1112-beta0615 335 11/12/2025
Loading failed

新增 11 种语言运行时本地化与带前缀日志,MapApi 支持按 Accept-Language 切换请求语言;修复天地图 POI 检索、失效密钥识别与 Nominatim 数组根解析;新增 NativeAOT/移动端冒烟与多 RID CI;确定性测试增至 98 个;升级 NewLife.Core 12.0.2026.1024 等依赖