Advertisement
am_dot_com

DDM 2022-01-04

Jan 4th, 2022 (edited)
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.69 KB | None | 0 0
  1. MainActivity.java
  2.  
  3. package com.joythis.android.gmaps22_2;
  4.  
  5. import androidx.appcompat.app.AppCompatActivity;
  6. import androidx.fragment.app.Fragment;
  7. import androidx.fragment.app.FragmentManager;
  8.  
  9. import android.os.Bundle;
  10. import android.view.View;
  11. import android.widget.AdapterView;
  12. import android.widget.Spinner;
  13.  
  14. import com.google.android.gms.maps.GoogleMap;
  15. import com.google.android.gms.maps.SupportMapFragment;
  16.  
  17. import java.util.Calendar;
  18.  
  19. public class MainActivity extends AppCompatActivity {
  20. public final static int CALLBACK_CODE_FOR_WHEN_PERMISSIONS_ARE_READY = 123;
  21. SupportMapFragment mMapFragment;
  22. FragmentManager mSupportFragmentManager;
  23.  
  24. AmGeoMap mAmGoogleMap;
  25. AmUtil mUtil;
  26.  
  27. Spinner mSpnMapType;
  28.  
  29. AdapterView.OnItemSelectedListener mItemSelectedHandler = new AdapterView.OnItemSelectedListener() {
  30. @Override
  31. public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
  32. String strSelectedOption = parent.getItemAtPosition(position).toString();
  33.  
  34. boolean bHybrid = strSelectedOption.compareToIgnoreCase(getString(R.string.strMapTypeHybrid))==0;
  35. boolean bNone = strSelectedOption.compareToIgnoreCase(getString(R.string.strMapTypeNone))==0;
  36. boolean bNormal = strSelectedOption.compareToIgnoreCase(getString(R.string.strMapTypeNormal))==0;
  37. boolean bSat = strSelectedOption.compareToIgnoreCase(getString(R.string.strMapTypeSatellite))==0;
  38. boolean bTerrain = strSelectedOption.compareToIgnoreCase(getString(R.string.strMapTypeTerrain))==0;
  39.  
  40. int iGoogleMapType = 0;
  41. if (bHybrid) iGoogleMapType = GoogleMap.MAP_TYPE_HYBRID;
  42. if (bNone) iGoogleMapType = GoogleMap.MAP_TYPE_NONE;
  43. if (bNormal) iGoogleMapType = GoogleMap.MAP_TYPE_NORMAL;
  44. if (bSat) iGoogleMapType = GoogleMap.MAP_TYPE_SATELLITE;
  45. if (bTerrain) iGoogleMapType = GoogleMap.MAP_TYPE_TERRAIN;
  46.  
  47. if (mAmGoogleMap !=null) mAmGoogleMap.changeMapType(iGoogleMapType);
  48. }//mItemSelectedHandler
  49.  
  50. @Override
  51. public void onNothingSelected(AdapterView<?> parent) {
  52. //do nothing
  53. }
  54. };//mItemSelectedHandler
  55.  
  56. final float
  57. DEF_LATITUDE=39.22086f, //ESGTS in decimal degrees
  58. DEF_LONGITUDE=-8.686735f, //ESGTS in decimal degrees
  59. DEF_ZOOM=18.0f; //higher value, closer shot
  60.  
  61. @Override
  62. protected void onCreate(Bundle savedInstanceState) {
  63. super.onCreate(savedInstanceState);
  64. setContentView(R.layout.rl_map);
  65.  
  66. init();
  67. }//onCreate
  68.  
  69. void init(){
  70. mUtil = new AmUtil(this);
  71.  
  72. mSupportFragmentManager = this.getSupportFragmentManager();
  73. mSpnMapType = findViewById(R.id.idSpnMapType);
  74. mSpnMapType.setOnItemSelectedListener(mItemSelectedHandler);
  75.  
  76. GeoUri someInitialLocation = new GeoUri(
  77. DEF_LATITUDE,
  78. DEF_LONGITUDE,
  79. DEF_ZOOM,
  80. "ESGTS",
  81. Calendar.getInstance()
  82. );
  83.  
  84. //AmGeoMap implements OnMapReadyCallback, so its objects can be arguments of getMapAsync
  85. mAmGoogleMap = new AmGeoMap(
  86. this,
  87. CALLBACK_CODE_FOR_WHEN_PERMISSIONS_ARE_READY,
  88. someInitialLocation
  89. );
  90.  
  91. Fragment f = mSupportFragmentManager.findFragmentById(R.id.idMap);
  92. mMapFragment = (SupportMapFragment) f;
  93. mMapFragment.getMapAsync(mAmGoogleMap);
  94. }//init
  95. }//MainActivity
  96.  
  97.  
  98. ****
  99. my_arrays.xml
  100.  
  101. <?xml version="1.0" encoding="utf-8"?>
  102. <resources>
  103. <string-array name="saMapTypes">
  104. <item>@string/strMapTypeHybrid</item>
  105. <item>@string/strMapTypeNone</item>
  106. <item>@string/strMapTypeNormal</item>
  107. <item>@string/strMapTypeSatellite</item>
  108. <item>@string/strMapTypeTerrain</item>
  109. </string-array>
  110. <string name="strMapTypeTerrain">Terrain</string>
  111. <string name="strMapTypeSatellite">Satellite</string>
  112. <string name="strMapTypeNormal">Normal</string>
  113. <string name="strMapTypeNone">None</string>
  114. <string name="strMapTypeHybrid">Hybrid</string>
  115. </resources>
  116.  
  117. ******
  118. fragment_to_be_included.xml
  119.  
  120. <?xml version="1.0" encoding="utf-8"?>
  121.  
  122. <fragment xmlns:android="http://schemas.android.com/apk/res/android"
  123. xmlns:map="http://schemas.android.com/apk/res-auto"
  124. xmlns:tools="http://schemas.android.com/tools"
  125. android:id="@+id/idMap"
  126. android:name="com.google.android.gms.maps.SupportMapFragment"
  127. android:layout_width="match_parent"
  128. android:layout_height="match_parent"
  129. tools:context=".MainActivity" />
  130.  
  131. <!--
  132. <fragment android:id="@+id/idMap"
  133. android:layout_width="match_parent"
  134. android:layout_height="wrap_content"
  135. class="com.google.android.gms.maps.MapFragment"
  136. xmlns:android="http://schemas.android.com/apk/res/android" />
  137. -->
  138.  
  139.  
  140.  
  141. ********
  142. rl_map.xml
  143.  
  144. <?xml version="1.0" encoding="utf-8"?>
  145. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  146. android:layout_width="match_parent" android:layout_height="match_parent">
  147.  
  148. <TextView
  149. android:id="@+id/idTvDashboard"
  150. android:layout_width="match_parent"
  151. android:layout_height="wrap_content"/>
  152.  
  153. <Spinner
  154. android:layout_below="@id/idTvDashboard"
  155. android:id="@+id/idSpnMapType"
  156. android:entries="@array/saMapTypes"
  157. android:layout_width="match_parent"
  158. android:layout_height="wrap_content"/>
  159.  
  160. <include
  161. android:layout_below="@id/idSpnMapType"
  162. android:layout_width="match_parent"
  163. android:layout_height="wrap_content"
  164. layout="@layout/fragment_to_be_included"/>
  165. </RelativeLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement