1. Download our Official Android App: Forums for Android!

Apps Unable to use SKMaps in android studio

Discussion in 'Android Development' started by Mrunal Ahirrao, Aug 15, 2016.

  1. Mrunal Ahirrao

    Thread Starter
    Rank:
    None
    Points:
    25
    Posts:
    3
    Joined:
    Aug 15, 2016

    Aug 15, 2016
    3
    0
    25
    Male
    Hello,
    I am trying to use SK maps SDK for Android, but I am facing some problems. I have followed as guided on this website :http://developer.skobbler.com/getting-started/android for integrating SDK in Android but still I am making mistake somewhere it seems. The problem is: As soon I launch the app, the first activity is correctly starting but as soon as SK maps library is initialised and the Map activity is created, the app crashes without showing any error. Here is my Initialization code:
    Code (Java):
    1. public class Map_initialization extends AppCompatActivity implements SKMapsInitializationListener {
    2. @Override
    3. public void onCreate(Bundle savedInstanceState) {
    4.     super.onCreate(savedInstanceState);
    5.     setContentView(R.layout.layout);
    6.     SKMaps.getInstance().initializeSKMaps(getApplication(),this);
    7. }
    8.  
    9. @Override
    10. public void onLibraryInitialized(boolean b) {  ///once maps initialized then go to map activity
    11.     Intent intent=new Intent(this,MainActivity.class);
    12.     startActivity(intent);
    13. }
    14. }
    Here is my Map Activity Code: Here map is created.

    Code (Java):
    1. public class MainActivity extends AppCompatActivity implements SKMapSurfaceListener {
    2.  
    3. double lat;
    4. double lng;
    5. float zoom_level=0;
    6. String Location="19.875692,75.353020";
    7. // get the annotation object
    8. SKAnnotation new_loc = new SKAnnotation(10); //marker which can be visible on map
    9.  
    10.  
    11. /**
    12. * Surface view for displaying the map
    13. */
    14. private SKMapSurfaceView mapView;
    15.  
    16. /**
    17. * the view that holds the map view
    18. */
    19. SKMapViewHolder mapHolder;
    20.  
    21. // get the callout view object from the map holder
    22. SKCalloutView mapPopup = mapHolder.getCalloutView();
    23.  
    24. @Override
    25. protected void onCreate(Bundle savedInstanceState) {
    26.     super.onCreate(savedInstanceState);
    27.     setContentView(R.layout.activity_main);
    28.     mapHolder = (SKMapViewHolder) findViewById(R.id.map_surface_holder);
    29. }
    30. @Override
    31. protected void onDestroy() {
    32.     super.onDestroy();
    33.     SKMaps.getInstance().destroySKMaps();
    34. }
    35.  
    36. public void Show_Location()
    37. {
    38.  
    39.     lat=Double.valueOf(Location.substring(0,9));//extracting latitude
    40.     lng=Double.valueOf(Location.substring(10,Location.length()));//extracting longitude
    41.     zoom_level=16;
    42.     new_loc.setAnnotationType(SKAnnotation.SK_ANNOTATION_TYPE_BLUE);
    43.     new_loc.setLocation(new SKCoordinate(lat,lng));
    44.     mapView.animateToZoomLevel(zoom_level);
    45.     mapView.animateToLocation(new SKCoordinate(lat,lng),1000);
    46.     mapView.addAnnotation(new_loc, SKAnimationSettings.ANIMATION_PIN_DROP);//adding marker
    47.  
    48.     // set the callout view’s background color
    49.     mapPopup.setViewColor(Color.argb(255, 200, 200, 255));
    50.     mapPopup.showAtLocation(new SKCoordinate(lat,lng),true);
    51. }
    52.  
    53. @Override
    54. protected void onPause() {
    55.     super.onPause();
    56.     mapHolder.onPause();
    57. }
    58.  
    59. @Override
    60. protected void onResume() {
    61.     super.onResume();
    62.     mapHolder.onResume();
    63. }
    64.  
    65. @Override
    66. public void onActionPan() {
    67.     zoom_level--;
    68.     mapView.setZoom(zoom_level);
    69. }
    70.  
    71. @Override
    72. public void onActionZoom() {
    73.     zoom_level++;
    74.     mapView.setZoom(zoom_level);
    75. }
    76.  
    77. @Override
    78. public void onSurfaceCreated(SKMapViewHolder skMapViewHolder) { //on map surface created
    79.     mapView = mapHolder.getMapSurfaceView();
    80.     mapView.getMapSettings().setMapPoiIconsShown(true);
    81.     mapView.getMapSettings().setMapPanningEnabled(true);
    82.     mapView.getMapSettings().setMapZoomingEnabled(true);
    83. }
    84.  
    85. @Override
    86. public void onMapRegionChanged(SKCoordinateRegion skCoordinateRegion) {
    87.  
    88. }
    89.  
    90. @Override
    91. public void onMapRegionChangeStarted(SKCoordinateRegion skCoordinateRegion) {
    92.  
    93. }
    94.  
    95. @Override
    96. public void onMapRegionChangeEnded(SKCoordinateRegion skCoordinateRegion) {
    97.  
    98. }
    99.  
    100. @Override
    101. public void onDoubleTap(SKScreenPoint skScreenPoint) {
    102.  
    103. }
    104.  
    105. @Override
    106. public void onSingleTap(SKScreenPoint skScreenPoint) {
    107.  
    108. }
    109.  
    110. @Override
    111. public void onRotateMap() {
    112.  
    113. }
    114.  
    115. @Override
    116. public void onLongPress(SKScreenPoint skScreenPoint) {
    117.  
    118. }
    119.  
    120. @Override
    121. public void onInternetConnectionNeeded() {
    122.  
    123. }
    124.  
    125. @Override
    126. public void onMapActionDown(SKScreenPoint skScreenPoint) {
    127.  
    128. }
    129.  
    130. @Override
    131. public void onMapActionUp(SKScreenPoint skScreenPoint) {
    132.  
    133. }
    134.  
    135. @Override
    136. public void onPOIClusterSelected(SKPOICluster skpoiCluster) {
    137.  
    138. }
    139.  
    140. @Override
    141. public void onMapPOISelected(SKMapPOI skMapPOI) {
    142.  
    143. }
    144.  
    145. @Override
    146. public void onAnnotationSelected(SKAnnotation skAnnotation) {
    147.  
    148. }
    149.  
    150. @Override
    151. public void onCustomPOISelected(SKMapCustomPOI skMapCustomPOI) {
    152.  
    153. }
    154.  
    155. @Override
    156. public void onCompassSelected() {
    157.  
    158. }
    159.  
    160. @Override
    161. public void onCurrentPositionSelected() {
    162.  
    163. }
    164.  
    165. @Override
    166. public void onObjectSelected(int i) {
    167.  
    168. }
    169.  
    170. @Override
    171. public void onInternationalisationCalled(int i) {
    172.  
    173. }
    174.  
    175. @Override
    176. public void onBoundingBoxImageRendered(int i) {
    177.  
    178. }
    179.  
    180. @Override
    181. public void onGLInitializationError(String s) {
    182.     Toast.makeText(getApplicationContext(),"ERROR:"+s,Toast.LENGTH_LONG).show();
    183.  
    184. }
    185.  
    186. @Override
    187. public void onScreenshotReady(Bitmap bitmap) {
    188.  
    189. }
    190. }
    Here is my gradle for app:

    Code (Text):
    1. buildscript {
    2. repositories {
    3.     mavenCentral()
    4. }
    5. dependencies {
    6.     classpath 'com.android.tools.build:gradle:2.1.2'
    7. }
    8. }
    9. //apply plugin: 'java'
    10. repositories {
    11. maven {
    12.     url "http://developer.skobbler.com/maven/"
    13. }
    14. }
    15.  
    16. configurations {
    17. skobblersdk
    18. }
    19. apply plugin: 'com.android.application'
    20. android {
    21.  
    22. compileSdkVersion 23
    23. buildToolsVersion "24.0.0"
    24. defaultConfig {
    25.     applicationId "com.example.ahirrao.gps"
    26.     minSdkVersion 16
    27.     targetSdkVersion 23
    28.     versionCode 1
    29.     versionName "1.0"
    30. }
    31.  
    32. buildTypes {
    33.     release {
    34.         minifyEnabled false
    35.         proguardFiles getDefaultProguardFile('proguard-android.txt'),      
    36.     'proguard-rules.pro'
    37.         signingConfig signingConfigs.config
    38.     }
    39.  
    40. dependencies {
    41. compile fileTree(include: ['*.jar'], dir: 'libs')
    42. testCompile 'junit:junit:4.12'
    43. compile 'com.android.support:appcompat-v7:23.4.0'
    44. skobblersdk "com.skobbler.ngx:SKMaps:3.0.0"
    45. compile files('libs/SKMaps.jar')
    46. }
    47.  
    48. def assetsPath = "$projectDir/src/main/assets"
    49. def libsPath = "$projectDir/libs"
    50. def jniLibsPath = "$projectDir/src/main/jniLibs"
    51.  
    52. task installSKMaps << {
    53. copy {
    54.     from configurations.skobblersdk
    55.     into "$buildDir/skobblersdk-down"
    56.     rename { String fileName -> 'skobblersdkres.zip' }
    57. }
    58. copy {
    59.     from zipTree("$buildDir/skobblersdk-down/skobblersdkres.zip")
    60.     into "$buildDir/skobblersdk-down"
    61. }
    62. delete("$jniLibsPath",
    63.         "$assetsPath/SKMaps.zip",
    64.         "$libsPath/SKMaps.jar")
    65. copy {
    66.     from "${buildDir}/skobblersdk-down/jniLibs"
    67.     into "$jniLibsPath"
    68. }
    69. copy {
    70.     from "${buildDir}/skobblersdk-down/"
    71.     into "$assetsPath"
    72. }
    73. copy {
    74.     from "${buildDir}/skobblersdk-down/SKMaps.jar"
    75.     into "$libsPath"
    76. }
    77. delete("$buildDir/skobblersdk-down")
    78. delete(configurations.skobblersdk)
    79. }
    This is my Layout for map:
    Code (Text):
    1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    2. android:layout_width="match_parent"
    3. android:layout_height="match_parent">
    4.  
    5. <com.skobbler.ngx.map.SKMapViewHolder
    6.     android:id="@+id/map_surface_holder"
    7.     android:layout_width="fill_parent"
    8.     android:layout_height="fill_parent" />
    9.  
    10.  
    11.  
    12. </RelativeLayout>
    And on the above website of Skobbler, they have given the code by using JAVA plugin in gradle but I am not able to use it as it is not compatible with android plugin. Please guide me.

     

    Advertisement

  2. HeavensSentSword

    HeavensSentSword Well-Known Member
    Rank:
    None
    Points:
    93
    Posts:
    134
    Joined:
    Jan 19, 2016

    Jan 19, 2016
    134
    36
    93
    Male
    You can just use the gradle way of importing it into you code. Are you using two different methods like using the jar file and the gradle way?That may cause issues with the build and won't use the right one.
     
    Mrunal Ahirrao likes this.
  3. Mrunal Ahirrao

    Thread Starter
    Rank:
    None
    Points:
    25
    Posts:
    3
    Joined:
    Aug 15, 2016

    Aug 15, 2016
    3
    0
    25
    Male
    Actuallly Gradle way is not working as it is required to use java plugin, now I am able to see maps, but etting problems in adding annotation.I am getting null pointer exception at mapView.
     
  4. Mrunal Ahirrao

    Thread Starter
    Rank:
    None
    Points:
    25
    Posts:
    3
    Joined:
    Aug 15, 2016

    Aug 15, 2016
    3
    0
    25
    Male
    Hi, I have am now able to use SKmaps.I was adding annotations to mapview without checking mapsurface.
     

Share This Page

Loading...