w3w java wrapper
3.1.21
Java库使用What3Words V3 API。
API方法分为一个单个服务对象,该对象可以通过What3Wordsv3实例进行中心管理。它将充当所有API端点的工厂,并将使用您的API键自动初始化它们。
要获取API密钥,请访问https://what3words.com/select-plan并注册一个帐户。
该工件可通过Maven Central获得。
< dependency >
< groupId >com.what3words</ groupId >
< artifactId >w3w-java-wrapper</ artifactId >
< version >3.1.19</ version >
</ dependency >
实现'com.what3words:w3w-java-wrapper:3.1.19'
请参阅What What 3words公共API文档
// For all requests a what3words API key is needed
What3WordsV3 api = new What3WordsV3 ( "what3words-api-key" );
// In the case that you run our Enterprise Suite API Server yourself, you may specify the URL to your own server like so:
//What3WordsV3 api = new What3WordsV3("what3words-api-key", "https://api.yourserver.com/v3/");
/**
* Additionally, if you run the Enterprise Suite API Server there is another optional setup() parameter: customHeaders.
* Use this if you need to send custom headers to your own server:
*/
//Map<String, String> headers = new HashMap<String, String>();
//headers.put("Name1", "Value1");
//headers.put("Name2", "Value2");
//What3WordsV3 api = new What3WordsV3("what3words-api-key", "https://api.yourserver.com/v3/", headers);
// Create and execute a request with the 3 word address such as "filled.count.soap"
ConvertToCoordinates coordinates = api . convertToCoordinates ( "filled.count.soap" ). execute ();
if ( coordinates . isSuccessful ()) { // the request was successful
System . out . println ( "Coordinates: " + coordinates );
} else { // the request was not successful
What3WordsError error = coordinates . getError ();
if ( error == What3WordsError . BAD_WORDS ) { // The three word address provided is invalid
System . out . println ( "BadWords: " + error . getMessage ());
} else if ( error == What3WordsError . INTERNAL_SERVER_ERROR ) { // Server Error
System . out . println ( "InternalServerError: " + error . getMessage ());
} else if ( error == What3WordsError . NETWORK_ERROR ) { // Network Error
System . out . println ( "NetworkError: " + error . getMessage ());
} else { // Unknown Error
System . out . println ( error + ": " + error . getMessage ());
}
}
检查字符串是否可能是What3words地址。提醒您,这只需检查文本的格式,因此为什么称为可能的3WA,以验证它是否是真实的What 3words地址,请使用有效的3个字地址。
Boolean isPossible = What3WordsV3 . isPossible3wa ( "filled.count.soap" ); // returns true
Boolean isPossible = What3WordsV3 . isPossible3wa ( "not a 3wa" ); // returns false
Boolean isPossible = What3WordsV3 . isPossible3wa ( "not.3wa address" ); //returns false
检查字符串是否可能是一个可能的What3Words地址,此正则允许不同的分隔符(即:不使用标准的全停止/点)。提醒您,这只需检查文本的格式,因此为什么称为DIDYOUMEAN3WA,以验证是否是真实的What 3words地址,请使用使用Full Stop作为分隔器有效的3个单词地址。
Boolean isDym = What3WordsV3 . didYouMean3wa ( "filled-count-soap" ); // returns true
Boolean isDym = What3WordsV3 . didYouMean3wa ( "not valid" ); // returns false
Boolean isDym = What3WordsV3 . didYouMean3wa ( "not.3wa address" ); // returns false
Boolean isDym = What3WordsV3 . didYouMean3wa ( "not.threewa address" ); // returns true
从文本中获取任何可能的3words地址。如果找不到可能的地址,将返回空列表。提醒您这只需检查文本的格式,因此为什么称为FindPossible3WA,以验证它是否是真实的What3words地址,请使用有效的3个字地址来验证列表的每个项目。
List < String > possible = What3WordsV3 . findPossible3wa ( "Please leave by my porch at filled.count.soap" ); //returns ["filled.count.soap"]
List < String > possible = What3WordsV3 . findPossible3wa ( "Please leave by my porch at filled.count.soap or deed.tulip.judge" ); // returns ["filled.count.soap", "deed.tulip.judge"]
List < String > possible = What3WordsV3 . findPossible3wa ( "Please leave by my porch at" ); // returns []