what3words v3 APIを使用するJavaライブラリ。
APIメソッドは、whow3wordsv3インスタンスで中央に管理できる単一のサービスオブジェクトにグループ化されます。すべての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'
what3words public 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と呼ばれるのはなぜかを確認するために、それが実際のwhat3wordsアドレスであるかどうかを確認してください。
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と呼ばれるのか、それが実際のwhat3wordsアドレスであるかどうかを確認するのはなぜですか?
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
テキストから可能なwhat3wordsアドレスを取得します。可能なアドレスが見つからない場合は、空のリストを返します。これはテキストの形式をチェックするだけなので、なぜFindPossible3WAと呼ばれるのか、それが実際のwhat3wordsアドレスであるかどうかを確認するのはなぜかを確認してください。
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 []