Location-Based Services (LBS) in On‑Site Fulfillment: Geofencing, Order Allocation, Routing and Autonomous Scheduling
This article explains how a location‑based service platform uses geofencing, R‑tree indexing, ray‑casting algorithms, and Elasticsearch GEO queries to determine service eligibility, allocate on‑site engineers, plan routes, and enable autonomous order scheduling for a C2B recycling business.
1 What is LBS
Location‑Based Services (LBS) use various positioning technologies to obtain the current location of a device and provide information and basic services via mobile internet. Users first determine their spatial position, then retrieve location‑related resources and information. LBS integrates mobile communications, internet, spatial positioning, location data, and big data, using a mobile‑internet platform for data updates and interaction.
2 Terminology
Engineer : On‑site fulfillment courier
Geofence : A closed polygon formed by points (latitude‑longitude vertices)
3 Business Overview
The "Zhuanzhuan" on‑site fulfillment service relies on a C2B model for 3C digital product recycling, offering fast and precise on‑site service. The workflow includes checking city support, address eligibility, valuation, order placement, automatic order assignment, and on‑site collection.
4 Geofence‑Based Exposure Ordering and Order Allocation
4.1 Exposure Ordering
Because on‑site collection cannot cover every city, accurately judging whether a user's address is within a supported area is crucial. The process converts the address to latitude‑longitude coordinates and checks if the point lies inside a geofence.
4.1.1 Preliminary Filter: Minimum Bounding Rectangle
Any irregular polygon can be enclosed by a rectangle defined by its top‑right and bottom‑left coordinates, allowing fast exclusion of most geofences.
4.1.2 Precise Filter: Ray‑Casting Method
The ray‑casting algorithm shoots a ray from the point in a direction and counts intersections with the polygon; an odd count means the point is inside, even means outside.
Common point‑in‑polygon methods include ray‑casting, corner‑angle, cross‑product, area, binary search, etc. The ray‑casting method was chosen for its simplicity and applicability to any polygon.
4.1.3 Simple Retrieval Process
Two stages: (1) Service loads geofence data from the database, builds an in‑memory index; (2) User query checks the point against the index using the chosen algorithm.
4.1.4 Retrieval Index
To avoid costly linear scans, an R‑tree index is built on the minimum bounding rectangles, reducing lookup complexity to O(log N).
4.2 Order Allocation
Unlike food delivery, the order density is lower, so a low‑cost, fast allocation method is needed. Engineers are attached to geofences representing their service area; when an order arrives, its coordinates are matched to a geofence, and the corresponding engineer is selected based on business rules.
5 Location‑Based Route Planning and Autonomous Order Scheduling
5.1 Route Planning
To improve fulfillment efficiency, the system calculates distances between orders and engineers. Simple straight‑line (great‑circle) distance is insufficient for complex terrain, so third‑party navigation services are used. Because synchronous calls would increase latency, the solution asynchronously invokes the navigation service, caches results, and combines them with business rules.
5.2 Autonomous Order Scheduling
When automated rules cannot handle complex scenarios, on‑site engineers can manually reassign orders. Two typical cases are described where engineers exchange orders based on proximity.
To quickly find nearby orders or engineers, Elasticsearch GEO queries are employed. Engineers periodically report their coordinates, orders store their coordinates, and GEO distance queries retrieve entities within a specified radius.
{
"filter": [{
"geo_distance": {
"location": {
"lat": 20.12345,
"lon": 100.223344
},
"distance": "3km",
"distance_type": "arc"
}
}]
}6 Summary
The article outlines several LBS‑driven scenarios for on‑site fulfillment, including geofence checking, order allocation, routing, and autonomous scheduling, and notes that as data volume grows, continuous optimization of retrieval and service mechanisms is required.
7 References
https://www.cnblogs.com/lbser/p/4471742.html
https://my.oschina.net/1024bits/blog/782820
https://www.cnblogs.com/yym2013/p/3673616.html
https://blog.csdn.net/WilliamSun0122/article/details/77994526
https://toutiao.io/posts/4as8i9/preview
Zhuanzhuan Tech
A platform for Zhuanzhuan R&D and industry peers to learn and exchange technology, regularly sharing frontline experience and cutting‑edge topics. We welcome practical discussions and sharing; contact waterystone with any questions.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.