All tutorials
Logistics
This tutorial outlines the steps to integrate what3words into a logistics system. More specifically, we will look at how to recognise a 3 word address that is attached to a delivery and how to convert that 3 word address into a coordinate. We’ll also look at how to include a what3words field into the system, so that employees can manually enter a 3 word address.
The end goal is that your logistics system will be able to handle deliveries with a 3 word address from entry to completion.
Using our API wrappers is a straightforward way of integrating quickly with our API. For full set up and installation details, check out our wrapper pages:
Java: https://developer.what3words.com/tutorial/java/
Python: https://developer.what3words.com/tutorial/python/
JavaScript: https://developer.what3words.com/tutorial/javascript/
PHP: https://developer.what3words.com/tutorial/php/
Swift: https://developer.what3words.com/tutorial/swift/
Objective-C: https://developer.what3words.com/tutorial/objective-c/
Android: https://developer.what3words.com/tutorial/android/
For every delivery flowing into your system, you will need to check whether it has a 3 word address as part of its information. While it is becoming more standard to pass 3 word addresses in a ‘what3words’ field, it is still common that 3 word addresses are passed in Address Line 1, 2 or 3, or a number of other fields. For this reason it’s best to check every field.
We check each field for a 3 word address by using a regular expression (RegEx). Our “full search” RegEx will only match a string that looks like a 3 word address e.g. “filled.count.soap” (or ///filled.count.soap).
You can find our ‘full’ RegEx below (see our RegEx tutorial here for more information):
String text = "index.home.raft"; String regex = "(?:\\p{L}\\p{M}*){1,}[.。。・・︒។։။۔።।](?:\\p{L}\\p{M}*){1,}[.。。・・︒។։။۔።।](?:\\p{L}\\p{M}*){1,}"; Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(text); if (matcher.find()) System.out.println(text + " is the format of a three word address"); else System.out.println(text + " is not a three word address");
text = "index.home.raft" regex = ur"[^0-9`~!@#$%^&*()+\-_=[{\]}\\|'<,.>?/\";:£§º©®\s]{1,}[.。。・・︒។։။۔።।][^0-9`~!@#$%^&*()+\-_=[{\]}\\|'<,.>?/\";:£§º©®\s]{1,}[.。。・・︒។։။۔።।][^0-9`~!@#$%^&*()+\-_=[{\]}\\|'<,.>?/\";:£§º©®\s]{1,}" if (re.search(regex, text, flags=re.UNICODE)): print(text + " is the format of a three word address") else: print(text + " is NOT a three word address")
let text = "index.home.raft" let regex_string = "\\w+[.。。・・︒។։။۔።।]\\w+[.。。・・︒។։။۔።।]\\w+" let regex = try! NSRegularExpression(pattern:regex_string, options: []) let count = regex.numberOfMatches(in: text, options: [], range: NSRange(text.startIndex.. 0) { print (text + " is the format of a three word address") } else { print (text + " is not a three word address") }
NSString *text = @"index.home.raft"; NSString *regex_string = @"\\w+[.。。・・︒។։။۔።।]\\w+[.。。・・︒។։။۔።।]\\w+"; NSError *error = NULL; NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:regex_string options:NSRegularExpressionCaseInsensitive error:&error]; NSUInteger match_count = [regex numberOfMatchesInString:text options:0 range:NSMakeRange(0, [text length])]; if (match_count > 0) NSLog(@"%@ is the format of a three word address.", text); else NSLog(@"%@ is not a three word address.", text);
var text = "index.home.raft"; var regex = /[^0-9`~!@#$%^&*()+\-_=[{\]}\\|'<,.>?/";:£§º©®\s]{1,}[.。。・・︒។։။۔።।][^0-9`~!@#$%^&*()+\-_=[{\]}\\|'<,.>?/";:£§º©®\s]{1,}[.。。・・︒។։။۔።।][^0-9`~!@#$%^&*()+\-_=[{\]}\\|'<,.>?/";:£§º©®\s]{1,}/ig; if (regex.test(text)) print(text + " is the format of a three word address"); else print(text + " is NOT a three word address");
$text = "index.home.raft"; $regex = '/(?:\p{L}\p{M}*){1,}[.。。・・︒។։။۔።।](?:\p{L}\p{M}*){1,}[.。。・・︒។։။۔።।](?:\p{L}\p{M}*){1,}/u'; if (preg_match($regex, $text)) print("$text is the format of a three word address\n"); else print("$text is NOT a three word address\n");
If a 3 word address is detected, we then need to convert this 3 word address into a coordinate, so that we can calculate routes etc.
Use the convert-to-coordinates
endpoint of the what3words API to obtain the latitude and longitude of the 3 word address. Store these coordinates as part of the delivery’s information.
Using our wrappers this can be done as follows:
// Convert a 3 word address to coordinates ConvertToCoordinates coordinates = api.convertToCoordinates("filled.count.soap") .execute(); System.out.println("Coordinates: " + coordinates);
W3wGeocoder.shared.convertToCoordinates(words: "filled.count.soap") { (place, error) in print(place?.coordinates.latitude, place?.coordinates.longitude) }
[api convertToCoordinates:@"filled.count.soap" format:JSON completion:^(W3wPlace *place, W3wError *error) { NSLog(@"Coordinates are: (%f, %f)", place.coordinates.latitude, place.coordinates.longitude); }];
what3words.api.convertToCoordinates("filled.count.soap").then(function(response) { console.log("[convertToCoordinates]", response); });
res = geocoder.convert_to_coordinates('prom.cape.pump') print(res)
$result = $api->convertToCordinates("filled.count.soap"); print_r($result);
It’s often the case that addressing information is gathered along the way in a delivery system. In such cases, it may be necessary to add a 3 word address to a delivery.
We can use the what3words AutoSuggest Component to quickly create an input field for a 3 word address, which includes AutoSuggest functionality that will automatically display a drop-down list of relevant 3 word address suggestions as your operative types. This greatly reduces errors on input.
You can find out more about the AutoSuggest Component here.
Development Checklist
- Get an API key
- Recognise a 3 word address attached to a delivery using a regular expression
- Convert the 3 word address into a coordinate using the what3words API.
- Add an input box for a 3 word address to your delivery system