Beta
Search SDK for Android

Japan search

Public beta for the Search API

The Mapbox Search API is in private beta for worldwide coverage and in public beta for Japan. Unless you are part of the private beta program, the Mapbox Search API is only available for Japanese-language queries for locations in Japan.

This example does not contain a UI. Results will be logged in Android Studio.

Note

This example is a part of the Search SDK for Android sample app. You can find the values for all referenced resources in the res directory. For example, see res/values/strings.xml for R.string.* references used in this example.

MainActivity.java
package com.mapbox.search.sample.api;
import android.os.Bundle;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import com.mapbox.search.ApiType;
import com.mapbox.search.Country;
import com.mapbox.search.Language;
import com.mapbox.search.MapboxSearchSdk;
import com.mapbox.search.ResponseInfo;
import com.mapbox.search.SearchEngine;
import com.mapbox.search.SearchEngineSettings;
import com.mapbox.search.SearchOptions;
import com.mapbox.search.SearchRequestTask;
import com.mapbox.search.SearchSelectionCallback;
import com.mapbox.search.result.SearchResult;
import com.mapbox.search.result.SearchSuggestion;
import com.mapbox.search.sample.BuildConfig;
import java.util.List;
public class JapanSearchJavaExampleActivity extends AppCompatActivity {
private SearchEngine searchEngine;
private SearchRequestTask searchRequestTask;
private final SearchSelectionCallback searchCallback = new SearchSelectionCallback() {
@Override
public void onSuggestions(@NonNull List<? extends SearchSuggestion> suggestions, @NonNull ResponseInfo responseInfo) {
if (suggestions.isEmpty()) {
Log.i("SearchApiExample", "No suggestions found");
} else {
Log.i("SearchApiExample", "Search suggestions: " + suggestions + "\nSelecting first...");
searchRequestTask = searchEngine.select(suggestions.get(0), this);
}
}
@Override
public void onResult(@NonNull SearchSuggestion suggestion, @NonNull SearchResult result, @NonNull ResponseInfo info) {
Log.i("SearchApiExample", "Search result: " + result);
}
@Override
public void onCategoryResult(@NonNull SearchSuggestion suggestion, @NonNull List<? extends SearchResult> results, @NonNull ResponseInfo responseInfo) {
Log.i("SearchApiExample", "Category search results: " + results);
}
@Override
public void onError(@NonNull Exception e) {
Log.i("SearchApiExample", "Search error: ", e);
}
};
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
searchEngine = MapboxSearchSdk.createSearchEngineWithBuiltInDataProviders(
ApiType.SBS,
new SearchEngineSettings(BuildConfig.MAPBOX_API_TOKEN)
);
final SearchOptions options = new SearchOptions.Builder()
.countries(Country.JAPAN)
.languages(Language.JAPANESE)
.build();
searchRequestTask = searchEngine.search("東京", options, searchCallback);
}
@Override
protected void onDestroy() {
searchRequestTask.cancel();
super.onDestroy();
}
}