今回は緯度経度から地理的情報(通り名,住所,地名、駅名等)を取得する方法です。
SKReverseGeocoderManager#reverseGeocodePositionに緯度経度を渡すだけです。
戻りがそのまま地理的情報になります。
サンプルではタップした位置の緯度経度の地理的情報を取得しています。
public class MainActivity extends AppCompatActivity {
private SKMapSurfaceView skMapSurfaceView;
private SKMapViewHolder mapHolder;
String mapResourcesDirPath;
private SKCoordinate startSkCoordinate = new SKCoordinate(139.766084, 35.681382);
SKMapSurfaceListener skMapSurfaceListener = new SKMapSurfaceListener() {
@Override
public void onSurfaceCreated(SKMapViewHolder skMapViewHolder) {
mapHolder = skMapViewHolder;
skMapSurfaceView = skMapViewHolder.getMapSurfaceView();
skMapSurfaceView.centerMapOnPosition(startSkCoordinate);
}
@Override
public void onSingleTap(SKScreenPoint skScreenPoint) {
//緯度経度から地理的情報(通り名,住所,地名、駅名等)を取得する。
SKSearchResult skSearchResult = SKReverseGeocoderManager.getInstance().reverseGeocodePosition(skMapSurfaceView.pointToCoordinate(skScreenPoint));
//検索結果のID
Log.d("SKSearchResult", "ID:" + skSearchResult.getId());
//検索結果の名前
Log.d("SKSearchResult", "Name:" + skSearchResult.getName());
//検索結果の緯度経度
Log.d("SKSearchResult", "Location" + skSearchResult.getLocation().toString());
//検索結果のメインカテゴリー
Log.d("SKSearchResult", "MainCategory:" + skSearchResult.getMainCategory());
//検索結果のカテゴリー
Log.d("SKSearchResult", "Category:" + skSearchResult.getCategory());
//検索結果のタイプ、通りの名前や地名
//http://developer.skobbler.com/docs/android/2.5.1/com/skobbler/ngx/search/SKSearchResult.SKSearchResultType.html
Log.d("SKSearchResult", "Type:" + skSearchResult.getType());
//検索結果が含まれるオフラインパッケージのコードを取得する。
Log.d("SKSearchResult", "OfflinePackageCode:" + skSearchResult.getOfflinePackageCode());
List<SKSearchResultParent> parentsList = skSearchResult.getParentsList();
Log.d("SKSearchResultParent", "SKSearchResultParent:" + parentsList.size());
for (SKSearchResultParent skSearchResultParent : parentsList) {
//検索結果が含まれる親要素のINDEXを表示する。
Log.d("SKSearchResultParent", "Index:" + skSearchResultParent.getParentIndex());
//検索結果が含まれる親要素の名前を表示する。
Log.d("SKSearchResultParent", "Name:" + skSearchResultParent.getParentName());
//検索結果が含まれる親要素のタイプを表示する。
//http://developer.skobbler.com/docs/android/2.5.1/com/skobbler/ngx/search/SKSearchResult.SKSearchResultType.html
Log.d("SKSearchResultParent", "Type:" + skSearchResultParent.getParentType());
}
}
@Override
public void onActionPan() {
}
@Override
public void onActionZoom() {
}
@Override
public void onMapRegionChanged(SKCoordinateRegion skCoordinateRegion) {
}
@Override
public void onMapRegionChangeStarted(SKCoordinateRegion skCoordinateRegion) {
}
@Override
public void onMapRegionChangeEnded(SKCoordinateRegion skCoordinateRegion) {
}
@Override
public void onDoubleTap(SKScreenPoint skScreenPoint) {
}
@Override
public void onRotateMap() {
}
@Override
public void onLongPress(SKScreenPoint skScreenPoint) {
}
@Override
public void onInternetConnectionNeeded() {
}
@Override
public void onMapActionDown(SKScreenPoint skScreenPoint) {
}
@Override
public void onMapActionUp(SKScreenPoint skScreenPoint) {
}
@Override
public void onPOIClusterSelected(SKPOICluster skpoiCluster) {
}
@Override
public void onMapPOISelected(SKMapPOI skMapPOI) {
}
@Override
public void onAnnotationSelected(SKAnnotation skAnnotation) {
}
@Override
public void onCustomPOISelected(SKMapCustomPOI skMapCustomPOI) {
}
@Override
public void onCompassSelected() {
}
@Override
public void onCurrentPositionSelected() {
}
@Override
public void onObjectSelected(int i) {
}
@Override
public void onInternationalisationCalled(int i) {
}
@Override
public void onBoundingBoxImageRendered(int i) {
}
@Override
public void onGLInitializationError(String s) {
}
@Override
public void onScreenshotReady(Bitmap bitmap) {
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mapResourcesDirPath = getFilesDir().getPath() + "/" + "SKMaps/";
if (!new File(mapResourcesDirPath).exists()) {
new SKPrepareMapTextureThread(this, mapResourcesDirPath, "SKMaps.zip", new SKPrepareMapTextureListener() {
@Override
public void onMapTexturesPrepared(boolean b) {
if (b) {
initMapSetting();
}
}
}).start();
} else {
initMapSetting();
}
}
@Override
protected void onPause() {
super.onPause();
if (mapHolder != null) {
mapHolder.onPause();
}
}
@Override
protected void onResume() {
super.onResume();
if (mapHolder != null) {
mapHolder.onResume();
}
}
private void initMapSetting() {
SKMapsInitSettings initMapSettings = new SKMapsInitSettings();
initMapSettings.setMapResourcesPaths(mapResourcesDirPath,
new SKMapViewStyle(mapResourcesDirPath + "daystyle/", "daystyle.json"));
final SKAdvisorSettings advisorSettings = initMapSettings.getAdvisorSettings();
advisorSettings.setAdvisorConfigPath(mapResourcesDirPath + "Advisor");
advisorSettings.setResourcePath(mapResourcesDirPath + "Advisor/Languages");
advisorSettings.setLanguage(SKAdvisorSettings.SKAdvisorLanguage.LANGUAGE_EN);
advisorSettings.setAdvisorVoice("en");
initMapSettings.setAdvisorSettings(advisorSettings);
SKMaps.getInstance().initializeSKMaps(this, initMapSettings);
SKMapFragment mapFragment = new SKMapFragment();
mapFragment.setMapSurfaceListener(skMapSurfaceListener);
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.add(R.id.container, mapFragment).commit();
}
}