Site icon C1CTech

Android Working with GoogleMap

<h3><strong><span style&equals;"color&colon; &num;000080&semi;">Android Google Map<&sol;span><&sol;strong><&sol;h3>&NewLine;<p class&equals;"p1"><span class&equals;"s1">Android provides facility to integrate Google map in our application by using <strong><span style&equals;"color&colon; &num;0000ff&semi;">Maps SDK for Android API&period;<&sol;span><&sol;strong><&sol;span><&sol;p>&NewLine;<p>With the <strong><span style&equals;"color&colon; &num;0000ff&semi;">Maps SDK for Android<&sol;span><&sol;strong>&comma; you can add maps based on Google Maps data to your application&period; The API automatically handles access to Google Maps servers&comma; data downloading&comma; map display&comma; and response to map gestures&period; You can also use API calls to add markers&comma; polygons&comma; and overlays to a basic map&comma; and to change the user&&num;8217&semi;s view of a particular map area&period; These objects provide additional information for map locations&comma; and allow user interaction with the map&period; The API allows you to add these graphics to a map&colon;<&sol;p>&NewLine;<ul>&NewLine;<li>Icons indicate a single location on the map &lpar;<strong><span style&equals;"color&colon; &num;008000&semi;">Markers<&sol;span><&sol;strong>&rpar;&period;<&sol;li>&NewLine;<li>Sets of line segments &lpar;<strong><span style&equals;"color&colon; &num;008000&semi;">Polylines<&sol;span><&sol;strong>&rpar;&period;<&sol;li>&NewLine;<li>Enclosed segments &lpar;<strong><span style&equals;"color&colon; &num;008000&semi;">Polygons<&sol;span><&sol;strong>&rpar;&period;<&sol;li>&NewLine;<li>Bitmap graphics that are tied to specific positions on the map &lpar;<strong><span style&equals;"color&colon; &num;008000&semi;">Ground Overlays<&sol;span><&sol;strong>&rpar;&period;<&sol;li>&NewLine;<li>Sets of images which are displayed on top of the base map tiles &lpar;<strong><span style&equals;"color&colon; &num;008000&semi;">Tile Overlays<&sol;span><&sol;strong>&rpar;&period;<&sol;li>&NewLine;<&sol;ul>&NewLine;<p>This article aims to give knowledge about how to implement Google Maps into your applications and also covered some basic topics&period;<&sol;p>&NewLine;<p>Let&&num;8217&semi;s start creating an example of Google map integration within our app&period;<&sol;p>&NewLine;<h3 class&equals;"h3"><strong><span style&equals;"color&colon; &num;000080&semi;">Creating New Project<&sol;span><&sol;strong><&sol;h3>&NewLine;<p>1&period;  Start Android Studio&period;<&sol;p>&NewLine;<p>2&period;  Create a new project as follows&colon;<&sol;p>&NewLine;<ul>&NewLine;<li>If you see the <span style&equals;"color&colon; &num;008000&semi;"><strong>Welcome to Android Studio<&sol;strong><&sol;span> dialog&comma; choose <span style&equals;"color&colon; &num;008000&semi;"><strong>Start a new Android Studio project<&sol;strong><&sol;span>&comma; available under &&num;8216&semi;Quick Start&&num;8217&semi; on the right of the dialog&period;<&sol;li>&NewLine;<li>Otherwise&comma; click <span style&equals;"color&colon; &num;008000&semi;"><strong>File<&sol;strong><&sol;span> in the Android Studio menu bar&comma; then <span style&equals;"color&colon; &num;008000&semi;"><strong>New<&sol;strong>&comma; <strong>New Project<&sol;strong>&period;<&sol;span><&sol;li>&NewLine;<&sol;ul>&NewLine;<p>3&period;  In the <span style&equals;"color&colon; &num;008000&semi;"><strong>Choose your project<&sol;strong><&sol;span> dialog&comma; select the tab that corresponds to the platform you intended to develop for&period; Most users will want to keep the default <span style&equals;"color&colon; &num;008000&semi;"><strong>Phone and Tablet<&sol;strong>&period;<&sol;span><&sol;p>&NewLine;<p>4&period;  Select <span style&equals;"color&colon; &num;008000&semi;"><strong>Google Maps Activity<&sol;strong>&comma;<&sol;span> then click <span style&equals;"color&colon; &num;008000&semi;"><strong>Next<&sol;strong><&sol;span>&period;<&sol;p>&NewLine;<p><img class&equals;"alignnone size-full wp-image-1283" src&equals;"https&colon;&sol;&sol;c1ctech&period;com&sol;wp-content&sol;uploads&sol;2019&sol;11&sol;Screenshot-2019-11-14-18&period;05&period;53&period;png" alt&equals;"Screenshot 2019-11-14 18&period;05&period;53" width&equals;"1806" height&equals;"1100" &sol;><&sol;p>&NewLine;<p>5&period;  Enter your app name&comma; package name&comma; and project location&comma; programming language &lpar;Java or Kotlin&rpar;&comma; and the minimum Android API level supported by your app&comma; then click <span style&equals;"color&colon; &num;008000&semi;"><strong>Finish<&sol;strong><&sol;span>&period;<&sol;p>&NewLine;<p><img class&equals;"alignnone size-full wp-image-1284" src&equals;"https&colon;&sol;&sol;c1ctech&period;com&sol;wp-content&sol;uploads&sol;2019&sol;11&sol;Screenshot-2019-11-14-18&period;10&period;13&period;png" alt&equals;"Screenshot 2019-11-14 18&period;10&period;13" width&equals;"1804" height&equals;"1130" &sol;><&sol;p>&NewLine;<p>6&period;  Copy the URL from <strong><span style&equals;"color&colon; &num;0000ff&semi;">google&lowbar;map&lowbar;api&period;xml<&sol;span><&sol;strong> file to generate Google map API key&period;<&sol;p>&NewLine;<p><img class&equals;"alignnone size-full wp-image-1285" src&equals;"https&colon;&sol;&sol;c1ctech&period;com&sol;wp-content&sol;uploads&sol;2019&sol;11&sol;Screenshot-2019-11-14-18&period;21&period;05-3276829616-1573828968230&period;png" alt&equals;"Screenshot 2019-11-14 18&period;21&period;05" width&equals;"1963" height&equals;"316" &sol;><&sol;p>&NewLine;<p>7&period;  Paste the copied URL at the browser&period; It will open the following page&period;<&sol;p>&NewLine;<p><img class&equals;"alignnone size-full wp-image-1286" src&equals;"https&colon;&sol;&sol;c1ctech&period;com&sol;wp-content&sol;uploads&sol;2019&sol;11&sol;Screenshot-2019-11-14-18&period;24&period;38&period;png" alt&equals;"Screenshot 2019-11-14 18&period;24&period;38" width&equals;"1078" height&equals;"504" &sol;><&sol;p>&NewLine;<p>8&period;  Click on Create API key to generate API key&period;<&sol;p>&NewLine;<p><img class&equals;"alignnone size-full wp-image-1288" src&equals;"https&colon;&sol;&sol;c1ctech&period;com&sol;wp-content&sol;uploads&sol;2019&sol;11&sol;Screenshot-2019-11-14-18&period;28&period;46&period;png" alt&equals;"Screenshot 2019-11-14 18&period;28&period;46" width&equals;"848" height&equals;"418" &sol;><&sol;p>&NewLine;<p>9&period;  After clicking on Create API key&comma; it will generate an API key displaying the following screen&period;<&sol;p>&NewLine;<p><img class&equals;"alignnone size-full wp-image-1290" src&equals;"https&colon;&sol;&sol;c1ctech&period;com&sol;wp-content&sol;uploads&sol;2019&sol;11&sol;Screenshot-2019-11-14-18&period;31&period;40&period;png" alt&equals;"Screenshot 2019-11-14 18&period;31&period;40" width&equals;"1592" height&equals;"796" &sol;><&sol;p>&NewLine;<p>10&period;  Copy this generated API key and paste it in your <span style&equals;"color&colon; &num;0000ff&semi;"><strong>google&lowbar;map&lowbar;api&period;xml<&sol;strong><&sol;span> file<&sol;p>&NewLine;<p><img class&equals;"alignnone size-full wp-image-1291" src&equals;"https&colon;&sol;&sol;c1ctech&period;com&sol;wp-content&sol;uploads&sol;2019&sol;11&sol;Screenshot-2019-11-14-18&period;34&period;28-2238297101-1573829461234&period;png" alt&equals;"Screenshot 2019-11-14 18&period;34&period;28" width&equals;"1974" height&equals;"310" &sol;><&sol;p>&NewLine;<p>11&period;  Open <span style&equals;"color&colon; &num;008000&semi;"><strong>build&period;gradle&period;<&sol;strong><&sol;span>Here you can see a new library to integrate google Maps gets added&period;<&sol;p>&NewLine;<p><span style&equals;"color&colon; &num;0000ff&semi;"><strong>build&period;gradle<&sol;strong><&sol;span><&sol;p>&NewLine;<pre>dependencies &lbrace;&NewLine; implementation fileTree&lpar;dir&colon; 'libs'&comma; include&colon; &lbrack;'&ast;&period;jar'&rsqb;&rpar;&NewLine; implementation 'androidx&period;appcompat&colon;appcompat&colon;1&period;1&period;0'&NewLine;&NewLine; <strong><span style&equals;"color&colon; &num;008000&semi;"> &sol;&sol;Google Map<&sol;span>&NewLine;<span style&equals;"color&colon; &num;0000ff&semi;"> implementation 'com&period;google&period;android&period;gms&colon;play-services-maps&colon;17&period;0&period;0'&NewLine;<&sol;span><&sol;strong> testImplementation 'junit&colon;junit&colon;4&period;12'&NewLine; androidTestImplementation 'androidx&period;test&colon;runner&colon;1&period;2&period;0'&NewLine; androidTestImplementation 'androidx&period;test&period;espresso&colon;espresso-core&colon;3&period;2&period;0'&NewLine;&rcub;<&sol;pre>&NewLine;<p>12&period;  Open  <strong><span style&equals;"color&colon; &num;008000&semi;">AndroidManifest&period;xml<&sol;span><&sol;strong> file and add the below user-permissions as shown below&period;<br &sol;>&NewLine;<strong><span style&equals;"color&colon; &num;0000ff&semi;"><em>INTERNET<&sol;em><&sol;span><&sol;strong> – To check internet connection status<br &sol;>&NewLine;<strong><span style&equals;"color&colon; &num;0000ff&semi;"><em>ACCESS&lowbar;COARSE&lowbar;LOCATION<&sol;em><&sol;span><&sol;strong> – To determine user’s location using WiFi and mobile cell data<br &sol;>&NewLine;<span style&equals;"color&colon; &num;0000ff&semi;"><strong><em>ACCESS&lowbar;FINE&lowbar;LOCATION<&sol;em><&sol;strong><&sol;span> – To determine user’s location using GPS&comma; WiFi and mobile cell data<&sol;p>&NewLine;<p><span style&equals;"color&colon; &num;0000ff&semi;"><strong>AndroidManifest&period;xml<&sol;strong><&sol;span><&excl;--&quest;xml version&equals;"1&period;0" encoding&equals;"utf-8"&quest;--><&sol;p>&NewLine;<pre>&lt&semi;&quest;xml version&equals;"1&period;0" encoding&equals;"utf-8"&quest;&gt&semi;&NewLine;&lt&semi;manifest xmlns&colon;android&equals;"http&colon;&sol;&sol;schemas&period;android&period;com&sol;apk&sol;res&sol;android"&NewLine; package&equals;"com&period;example&period;googlemapdemo"&gt&semi;&NewLine;&NewLine; <strong><span style&equals;"color&colon; &num;008000&semi;"> &lt&semi;uses-permission android&colon;name&equals;"android&period;permission&period;ACCESS&lowbar;FINE&lowbar;LOCATION" &sol;&gt&semi;<&sol;span><&sol;strong>&NewLine;<strong><span style&equals;"color&colon; &num;008000&semi;"> &lt&semi;uses-permission android&colon;name&equals;"android&period;permission&period;ACCESS&lowbar;COARSE&lowbar;LOCATION" &sol;&gt&semi;<&sol;span><&sol;strong>&NewLine;<strong><span style&equals;"color&colon; &num;008000&semi;"> &lt&semi;uses-permission android&colon;name&equals;"android&period;permission&period;INTERNET" &sol;&gt&semi;<&sol;span><&sol;strong>&NewLine;&NewLine; &lt&semi;application&NewLine; android&colon;allowBackup&equals;"true"&NewLine; android&colon;icon&equals;"&commat;mipmap&sol;ic&lowbar;launcher"&NewLine; android&colon;label&equals;"&commat;string&sol;app&lowbar;name"&NewLine; android&colon;roundIcon&equals;"&commat;mipmap&sol;ic&lowbar;launcher&lowbar;round"&NewLine; android&colon;supportsRtl&equals;"true"&NewLine; android&colon;theme&equals;"&commat;style&sol;AppTheme"&gt&semi;&NewLine;&NewLine;&NewLine; &lt&semi;activity&NewLine; android&colon;name&equals;"&period;MapsActivity"&NewLine; android&colon;label&equals;"&commat;string&sol;title&lowbar;activity&lowbar;maps"&gt&semi;&NewLine; &lt&semi;intent-filter&gt&semi;&NewLine; &lt&semi;action android&colon;name&equals;"android&period;intent&period;action&period;MAIN" &sol;&gt&semi;&NewLine;&NewLine; &lt&semi;category android&colon;name&equals;"android&period;intent&period;category&period;LAUNCHER" &sol;&gt&semi;&NewLine; &lt&semi;&sol;intent-filter&gt&semi;&NewLine; &lt&semi;&sol;activity&gt&semi;&NewLine;&NewLine; &lt&semi;meta-data&NewLine; android&colon;name&equals;"com&period;google&period;android&period;geo&period;API&lowbar;KEY"&NewLine; android&colon;value&equals;"&commat;string&sol;google&lowbar;maps&lowbar;key" &sol;&gt&semi;&NewLine; &lt&semi;&sol;application&gt&semi;&NewLine;&NewLine;&NewLine;&NewLine;&lt&semi;&sol;manifest&gt&semi;<&sol;pre>&NewLine;<p>13&period;  Google maps are implemented using <span style&equals;"color&colon; &num;008000&semi;"><strong>Support<&sol;strong><strong>MapFragment<&sol;strong><&sol;span> which is a subclass of <span style&equals;"color&colon; &num;008000&semi;"><strong>Fragment<&sol;strong><&sol;span> class&period; By default&comma; the XML file that defines the app&&num;8217&semi;s layout is at <strong>res&sol;layout&sol;activity&lowbar;maps&period;xml<&sol;strong>&period; It contains the following code&colon;<&sol;p>&NewLine;<p class&equals;"h3"><strong><span style&equals;"color&colon; &num;0000ff&semi;">activity&lowbar;maps&period;xml<&sol;span><&sol;strong><&excl;--&quest;xml version&equals;"1&period;0" encoding&equals;"utf-8"&quest;--><&sol;p>&NewLine;<pre>&lt&semi;&quest;xml version&equals;"1&period;0" encoding&equals;"utf-8"&quest;&gt&semi;&NewLine;&lt&semi;fragment xmlns&colon;android&equals;"http&colon;&sol;&sol;schemas&period;android&period;com&sol;apk&sol;res&sol;android"&NewLine; xmlns&colon;map&equals;"http&colon;&sol;&sol;schemas&period;android&period;com&sol;apk&sol;res-auto"&NewLine; xmlns&colon;tools&equals;"http&colon;&sol;&sol;schemas&period;android&period;com&sol;tools"&NewLine; android&colon;id&equals;"&commat;&plus;id&sol;map"&NewLine; android&colon;name&equals;"com&period;google&period;android&period;gms&period;maps&period;SupportMapFragment"&NewLine; android&colon;layout&lowbar;width&equals;"match&lowbar;parent"&NewLine; android&colon;layout&lowbar;height&equals;"match&lowbar;parent"&NewLine; tools&colon;context&equals;"&period;MapsActivity" &sol;&gt&semi;<&sol;pre>&NewLine;<p>14&period;  To get the GoogleMap object in our <span style&equals;"color&colon; &num;008000&semi;"><strong>MapsActivity&period;java<&sol;strong><&sol;span> class we need to implement the <strong><span style&equals;"color&colon; &num;008000&semi;">OnMapReadyCallback<&sol;span><&sol;strong> interface and override the <strong><span style&equals;"color&colon; &num;008000&semi;">onMapReady&lpar;&rpar;<&sol;span><&sol;strong> callback method&period;<&sol;p>&NewLine;<p class&equals;"h3"><strong><span style&equals;"color&colon; &num;0000ff&semi;">MapsActivity&period;java<&sol;span><&sol;strong><&sol;p>&NewLine;<pre>package com&period;example&period;googlemapdemo&semi;&NewLine;&NewLine;import android&period;os&period;Bundle&semi;&NewLine;&NewLine;import com&period;google&period;android&period;gms&period;maps&period;CameraUpdateFactory&semi;&NewLine;import com&period;google&period;android&period;gms&period;maps&period;GoogleMap&semi;&NewLine;import com&period;google&period;android&period;gms&period;maps&period;OnMapReadyCallback&semi;&NewLine;import com&period;google&period;android&period;gms&period;maps&period;SupportMapFragment&semi;&NewLine;import com&period;google&period;android&period;gms&period;maps&period;model&period;LatLng&semi;&NewLine;import com&period;google&period;android&period;gms&period;maps&period;model&period;MarkerOptions&semi;&NewLine;&NewLine;import androidx&period;fragment&period;app&period;FragmentActivity&semi;&NewLine;&NewLine;public class MapsActivity extends FragmentActivity implements OnMapReadyCallback &lbrace;&NewLine;&NewLine; private GoogleMap mMap&semi;&NewLine;&NewLine; &commat;Override&NewLine; protected void onCreate&lpar;Bundle savedInstanceState&rpar; &lbrace;&NewLine; super&period;onCreate&lpar;savedInstanceState&rpar;&semi;&NewLine; setContentView&lpar;R&period;layout&period;activity&lowbar;maps&rpar;&semi;&NewLine; &NewLine; <strong><span style&equals;"color&colon; &num;008000&semi;">&sol;&sol; Obtain the SupportMapFragment and get notified when the map is ready to be used&period;<&sol;span><&sol;strong>&NewLine; SupportMapFragment mapFragment &equals; &lpar;SupportMapFragment&rpar; getSupportFragmentManager&lpar;&rpar;&NewLine; &period;findFragmentById&lpar;R&period;id&period;map&rpar;&semi;&NewLine; mapFragment&period;getMapAsync&lpar;this&rpar;&semi;&NewLine; &rcub;&NewLine;&NewLine;&NewLine; <strong><span style&equals;"color&colon; &num;008000&semi;">&sol;&ast;&ast;<&sol;span><&sol;strong>&NewLine;<strong><span style&equals;"color&colon; &num;008000&semi;"> &ast; Manipulates the map once available&period;<&sol;span><&sol;strong>&NewLine;<strong><span style&equals;"color&colon; &num;008000&semi;"> &ast; This callback is triggered when the map is ready to be used&period;<&sol;span><&sol;strong>&NewLine;<strong><span style&equals;"color&colon; &num;008000&semi;"> &ast; This is where we can add markers or lines&comma; add listeners or move the camera&period; In this case&comma;<&sol;span><&sol;strong>&NewLine;<strong><span style&equals;"color&colon; &num;008000&semi;"> &ast; we just add a marker near Sydney&comma; Australia&period;<&sol;span><&sol;strong>&NewLine;<strong><span style&equals;"color&colon; &num;008000&semi;"> &ast; If Google Play services is not installed on the device&comma; the user will be prompted to install<&sol;span><&sol;strong>&NewLine;<strong><span style&equals;"color&colon; &num;008000&semi;"> &ast; it inside the SupportMapFragment&period; This method will only be triggered once the user has<&sol;span><&sol;strong>&NewLine;<strong><span style&equals;"color&colon; &num;008000&semi;"> &ast; installed Google Play services and returned to the app&period;<&sol;span><&sol;strong>&NewLine;<strong><span style&equals;"color&colon; &num;008000&semi;"> &ast;&sol;<&sol;span><&sol;strong>&NewLine; &NewLine; &commat;Override&NewLine; public void onMapReady&lpar;GoogleMap googleMap&rpar; &lbrace;&NewLine; mMap &equals; googleMap&semi;&NewLine;&NewLine; <strong><span style&equals;"color&colon; &num;008000&semi;">&sol;&sol; Add a marker in Sydney and move the camera<&sol;span><&sol;strong>&NewLine; LatLng sydney &equals; new LatLng&lpar;-34&comma; 151&rpar;&semi;&NewLine; mMap&period;addMarker&lpar;new MarkerOptions&lpar;&rpar;&period;position&lpar;sydney&rpar;&period;title&lpar;"Marker in Sydney"&rpar;&rpar;&semi;&NewLine; mMap&period;moveCamera&lpar;CameraUpdateFactory&period;newLatLng&lpar;sydney&rpar;&rpar;&semi;&NewLine; &rcub;&NewLine;&rcub;<&sol;pre>&NewLine;<p>When you run your app it will look like this as shown below&colon;<&sol;p>&NewLine;<p><img class&equals;"alignnone wp-image-1292" src&equals;"https&colon;&sol;&sol;c1ctech&period;com&sol;wp-content&sol;uploads&sol;2019&sol;11&sol;Screenshot&lowbar;1573738600&period;png" alt&equals;"Screenshot&lowbar;1573738600" width&equals;"362" height&equals;"643" &sol;><&sol;p>&NewLine;<&excl;-- WP QUADS Content Ad Plugin v&period; 2&period;0&period;98&period;1 -->&NewLine;<div class&equals;"quads-location quads-ad2" id&equals;"quads-ad2" style&equals;"float&colon;none&semi;margin&colon;0px&semi;">&NewLine;&NewLine;<&sol;div>&NewLine;&NewLine;<h3><strong><span style&equals;"color&colon; &num;000080&semi;">Changing Map Type<&sol;span><&sol;strong><&sol;h3>&NewLine;<p>Google provides 4 kinds of map types <span style&equals;"color&colon; &num;0000ff&semi;"><strong>Normal<&sol;strong>&comma; <strong>Hybrid<&sol;strong>&comma; <strong>Satellite<&sol;strong><&sol;span> and <span style&equals;"color&colon; &num;0000ff&semi;"><strong>Terrain<&sol;strong><&sol;span>&period; You can toggle to any kind of map using <strong><span style&equals;"color&colon; &num;008000&semi;"><em>googleMap&period;setMapType&lpar;&rpar;<&sol;em><&sol;span><&sol;strong> method&period;<&sol;p>&NewLine;<pre>googleMap&period;setMapType&lpar;GoogleMap&period;MAP&lowbar;TYPE&lowbar;NORMAL&rpar;&semi;&NewLine;googleMap&period;setMapType&lpar;GoogleMap&period;MAP&lowbar;TYPE&lowbar;HYBRID&rpar;&semi;&NewLine;googleMap&period;setMapType&lpar;GoogleMap&period;MAP&lowbar;TYPE&lowbar;SATELLITE&rpar;&semi;&NewLine;googleMap&period;setMapType&lpar;GoogleMap&period;MAP&lowbar;TYPE&lowbar;TERRAIN&rpar;&semi;&NewLine;googleMap&period;setMapType&lpar;GoogleMap&period;MAP&lowbar;TYPE&lowbar;NONE&rpar;&semi;<&sol;pre>&NewLine;<p><span style&equals;"color&colon; &num;0000ff&semi;"><strong>NORMAL<&sol;strong><&sol;span>                                                                                         <span style&equals;"color&colon; &num;0000ff&semi;"><strong>HYBRID<&sol;strong><&sol;span><&sol;p>&NewLine;<h2><img class&equals;"alignnone wp-image-1295" src&equals;"https&colon;&sol;&sol;c1ctech&period;com&sol;wp-content&sol;uploads&sol;2019&sol;11&sol;Screenshot&lowbar;1573741746&period;png" alt&equals;"Screenshot&lowbar;1573741746" width&equals;"304" height&equals;"540" &sol;>     <img class&equals;"alignnone wp-image-1296" style&equals;"color&colon; var&lpar;--color-text&rpar;&semi; font-size&colon; 16px&semi; font-weight&colon; 400&semi;" src&equals;"https&colon;&sol;&sol;c1ctech&period;com&sol;wp-content&sol;uploads&sol;2019&sol;11&sol;Screenshot&lowbar;1573741785&period;png" alt&equals;"Screenshot&lowbar;1573741785" width&equals;"304" height&equals;"540" &sol;><&sol;h2>&NewLine;<h3><img class&equals;"alignnone wp-image-1297" src&equals;"https&colon;&sol;&sol;c1ctech&period;com&sol;wp-content&sol;uploads&sol;2019&sol;11&sol;Screenshot&lowbar;1573742071&period;png" alt&equals;"Screenshot&lowbar;1573742071" width&equals;"304" height&equals;"541" &sol;>       <img class&equals;"alignnone wp-image-1298" src&equals;"https&colon;&sol;&sol;c1ctech&period;com&sol;wp-content&sol;uploads&sol;2019&sol;11&sol;Screenshot&lowbar;1573742129&period;png" alt&equals;"Screenshot&lowbar;1573742129" width&equals;"302" height&equals;"537" &sol;><&sol;h3>&NewLine;<p><span style&equals;"color&colon; &num;0000ff&semi;"><strong>SATELLITE<&sol;strong><&sol;span>                                                                                   <span style&equals;"color&colon; &num;0000ff&semi;"><strong>TERRAIN<&sol;strong><&sol;span><&sol;p>&NewLine;<h3><span style&equals;"color&colon; &num;000080&semi;"><strong>Placing a Marker<&sol;strong><&sol;span><&sol;h3>&NewLine;<p>You can place a marker on the map by using the following code&period;<&sol;p>&NewLine;<pre><strong><span style&equals;"color&colon; &num;008000&semi;">&sol;&sol; latitude and longitude<&sol;span><&sol;strong>&NewLine; double latitude &equals; &semi;&NewLine; double longitude &equals; &semi;&NewLine;&NewLine; <strong><span style&equals;"color&colon; &num;008000&semi;">&sol;&sol; create marker<&sol;span><&sol;strong>&NewLine; MarkerOptions marker &equals; new MarkerOptions&lpar;&rpar;&period;position&lpar;new LatLng&lpar;latitude&comma; longitude&rpar;&rpar;&period;title&lpar;"Hello Maps "&rpar;&semi;&NewLine;&NewLine;<strong><span style&equals;"color&colon; &num;008000&semi;">&sol;&sol; adding marker<&sol;span><&sol;strong>&NewLine;googleMap&period;addMarker&lpar;marker&rpar;&semi;<&sol;pre>&NewLine;<h4><span style&equals;"color&colon; &num;0000ff&semi;"><strong> Output<&sol;strong><&sol;span><&sol;h4>&NewLine;<p><img class&equals;"alignnone wp-image-1293" src&equals;"https&colon;&sol;&sol;c1ctech&period;com&sol;wp-content&sol;uploads&sol;2019&sol;11&sol;Screenshot&lowbar;1573740860&period;png" alt&equals;"Screenshot&lowbar;1573740860" width&equals;"369" height&equals;"656" &sol;><&sol;p>&NewLine;<h3><strong><span style&equals;"color&colon; &num;000080&semi;">Changing Marker Color<&sol;span><&sol;strong><&sol;h3>&NewLine;<p>By default map marker color will be RED&period; Google maps provides some set of predefined colored icons for the marker&period;<&sol;p>&NewLine;<pre><span style&equals;"color&colon; &num;008000&semi;"><strong>&sol;&sol; ROSE color icon<&sol;strong><&sol;span>&NewLine;marker&period;icon&lpar;BitmapDescriptorFactory&period;defaultMarker&lpar;BitmapDescriptorFactory&period;HUE&lowbar;ROSE&rpar;&rpar;&semi;&NewLine;&NewLine;<strong><span style&equals;"color&colon; &num;008000&semi;">&sol;&sol; GREEN color icon<&sol;span><&sol;strong>&NewLine;marker&period;icon&lpar;BitmapDescriptorFactory&period;defaultMarker&lpar;BitmapDescriptorFactory&period;HUE&lowbar;GREEN&rpar;&rpar;&semi;<&sol;pre>&NewLine;<p>You can set the following predefined colored icons for the marker&colon;<&sol;p>&NewLine;<p class&equals;"p1"><span style&equals;"color&colon; &num;0000ff&semi;"><strong> HUE&lowbar;AZURE<span class&equals;"Apple-converted-space">          <&sol;span> <span class&equals;"Apple-converted-space">  <&sol;span>HUE&lowbar;BLUE <span class&equals;"Apple-converted-space">   <&sol;span><&sol;strong><&sol;span><&sol;p>&NewLine;<p class&equals;"p1"><span style&equals;"color&colon; &num;0000ff&semi;"><strong> HUE&lowbar;CYAN <span class&equals;"Apple-converted-space">            <&sol;span> <span class&equals;"Apple-converted-space">  <&sol;span>HUE&lowbar;GREEN<span class&equals;"Apple-converted-space">   <&sol;span><&sol;strong><&sol;span><&sol;p>&NewLine;<p class&equals;"p1"><span style&equals;"color&colon; &num;0000ff&semi;"><strong> HUE&lowbar;MAGENTA     <span class&equals;"Apple-converted-space">  <&sol;span>HUE&lowbar;ORANGE <&sol;strong><&sol;span><&sol;p>&NewLine;<p class&equals;"p1"><span style&equals;"color&colon; &num;0000ff&semi;"><strong><span class&equals;"Apple-converted-space"> <&sol;span>HUE&lowbar;RED                 <span class&equals;"Apple-converted-space">   <&sol;span>HUE&lowbar;ROSE <span class&equals;"Apple-converted-space">   <&sol;span><&sol;strong><&sol;span><&sol;p>&NewLine;<p class&equals;"p1"><span style&equals;"color&colon; &num;0000ff&semi;"><strong><span class&equals;"Apple-converted-space"> <&sol;span>HUE&lowbar;VIOLET          <span class&equals;"Apple-converted-space">   <&sol;span>HUE&lowbar;YELLOW<&sol;strong><&sol;span><&sol;p>&NewLine;<h3><strong><span style&equals;"color&colon; &num;000080&semi;">Custom Marker Icon<&sol;span><&sol;strong><&sol;h3>&NewLine;<p>Apart from maps native marker icons&comma; you can use own image to show as a marker&period; You can load the icon from any kind of supported sources&period;<&sol;p>&NewLine;<p><span style&equals;"color&colon; &num;0000ff&semi;"><strong>fromAsset&lpar;String assetName&rpar;<&sol;strong><&sol;span> – Loading from assets folder<br &sol;>&NewLine;<strong><span style&equals;"color&colon; &num;0000ff&semi;"><em>fromBitmap &lpar;Bitmap image&rpar;<&sol;em> <&sol;span><&sol;strong>– Loading bitmap image<br &sol;>&NewLine;<em>f<strong><span style&equals;"color&colon; &num;0000ff&semi;">romFile &lpar;String path&rpar;<&sol;span><&sol;strong><&sol;em> – Loading from file<br &sol;>&NewLine;<strong><span style&equals;"color&colon; &num;0000ff&semi;"><em>fromResource &lpar;int resourceId&rpar;<&sol;em><&sol;span><&sol;strong> – Loading from drawable resource<&sol;p>&NewLine;<p>Below I loaded a custom marker icon from <span style&equals;"color&colon; &num;008000&semi;"><strong>drawable<&sol;strong><&sol;span> folder<&sol;p>&NewLine;<pre><strong><span style&equals;"color&colon; &num;008000&semi;"> &sol;&sol; latitude and longitude<&sol;span><&sol;strong>&NewLine; double latitude &equals; 12&period;9716&semi;&NewLine; double longitude &equals; 77&period;5946&semi;&NewLine;&NewLine; <span style&equals;"color&colon; &num;008000&semi;"><strong> &sol;&sol; create marker<&sol;strong><&sol;span>&NewLine; MarkerOptions marker &equals; new MarkerOptions&lpar;&rpar;&period;position&lpar;new LatLng&lpar;latitude&comma; longitude&rpar;&rpar;&period;title&lpar;"Hello Maps"&rpar;&semi;&NewLine;&NewLine;<strong><span style&equals;"color&colon; &num;008000&semi;">&sol;&sol; Changing marker icon<&sol;span><&sol;strong>&NewLine;marker&period;icon&lpar;BitmapDescriptorFactory&period;fromResource&lpar;R&period;drawable&period;my&lowbar;marker&lowbar;icon&rpar;&rpar;&rpar;&semi;&NewLine;&NewLine;<strong><span style&equals;"color&colon; &num;008000&semi;"> &sol;&sol; adding marker<&sol;span><&sol;strong>&NewLine; googleMap&period;addMarker&lpar;marker&rpar;&semi;<&sol;pre>&NewLine;<h3 id&equals;"ui&lowbar;controls"><strong><span style&equals;"color&colon; &num;000080&semi;">UI controls<&sol;span><&sol;strong><&sol;h3>&NewLine;<p>The Maps API offers built-in UI controls that are similar to those found in the Google Maps application on your Android phone&period; You can toggle the visibility of these controls using the <span style&equals;"color&colon; &num;0000ff&semi;"><strong>UiSettings<&sol;strong><&sol;span> class which can be obtained from a <strong><span style&equals;"color&colon; &num;008000&semi;">GoogleMap<&sol;span><&sol;strong> with the <strong><span style&equals;"color&colon; &num;008000&semi;">GoogleMap&period;getUiSettings<&sol;span><&sol;strong> method&period;<&sol;p>&NewLine;<h4><span style&equals;"color&colon; &num;0000ff&semi;"><strong>Zoom Controls<&sol;strong><&sol;span><&sol;h4>&NewLine;<p>You can call <strong><span style&equals;"color&colon; &num;008000&semi;"><em>setZoomControlsEnabled&lpar;&rpar;<&sol;em> <&sol;span><&sol;strong>function to enable zooming controls on the map&period; By disabling these buttons map zooming functionality still work by pinching gesture&period; These are disabled by default but can be enabled by calling <strong><span style&equals;"color&colon; &num;008000&semi;"><em>setZoomControlsEnabled&lpar;&rpar; <&sol;em><&sol;span><&sol;strong><span style&equals;"color&colon; &num;000000&semi;">method<&sol;span><&sol;p>&NewLine;<pre>googleMap&period;getUiSettings&lpar;&rpar;&period;setZoomControlsEnabled&lpar;true&rpar;&semi;<&sol;pre>&NewLine;<h2><img class&equals;"alignnone wp-image-1299" src&equals;"https&colon;&sol;&sol;c1ctech&period;com&sol;wp-content&sol;uploads&sol;2019&sol;11&sol;Screenshot&lowbar;1573743650&period;png" alt&equals;"Screenshot&lowbar;1573743650" width&equals;"368" height&equals;"654" &sol;><&sol;h2>&NewLine;<h4><strong><span style&equals;"color&colon; &num;0000ff&semi;">Compass<&sol;span><&sol;strong><&sol;h4>&NewLine;<p>The compass will only ever appear when the camera is oriented such that it has a non-zero bearing or non-zero tilt&period; When the user clicks on the compass&comma; the camera animates back to a position with bearing and tilt of zero &lpar;the default orientation&rpar; and the compass fades away shortly afterwards&period; You can disable the compass appearing altogether by calling <strong><span style&equals;"color&colon; &num;008000&semi;"><em>setCompassEnabled&lpar;&rpar;<&sol;em><&sol;span><&sol;strong> function<&sol;p>&NewLine;<pre>googleMap&period;getUiSettings&lpar;&rpar;&period;setCompassEnabled&lpar;false&rpar;&semi;<&sol;pre>&NewLine;<h2><img class&equals;"alignnone size-full wp-image-1300" src&equals;"https&colon;&sol;&sol;c1ctech&period;com&sol;wp-content&sol;uploads&sol;2019&sol;11&sol;compass&lowbar;img&period;png" alt&equals;"compass&lowbar;img" width&equals;"320" height&equals;"480" &sol;><&sol;h2>&NewLine;<h4><strong><span style&equals;"color&colon; &num;0000ff&semi;">My Location Button<&sol;span><&sol;strong><&sol;h4>&NewLine;<p>My location button will be used to move map to your current location&period; This button can be shown &sol; hidden by calling <strong><span style&equals;"color&colon; &num;008000&semi;"><em>setMyLocationButtonEnabled&lpar;&rpar;<&sol;em><&sol;span><&sol;strong> function<&sol;p>&NewLine;<pre>googleMap&period;getUiSettings&lpar;&rpar;&period;setMyLocationButtonEnabled&lpar;true&rpar;&semi;<&sol;pre>&NewLine;<h4><img class&equals;"alignnone size-full wp-image-1302" src&equals;"https&colon;&sol;&sol;c1ctech&period;com&sol;wp-content&sol;uploads&sol;2019&sol;11&sol;mylocationbutton&lowbar;img&period;png" alt&equals;"mylocationbutton&lowbar;img" width&equals;"320" height&equals;"480" &sol;><&sol;h4>&NewLine;<h4><span style&equals;"color&colon; &num;0000ff&semi;"><strong>Level Picker<&sol;strong><&sol;span><&sol;h4>&NewLine;<p><span style&equals;"color&colon; var&lpar;--color-text&rpar;&semi;">The indoor map is normally shown with a level picker&comma; which shows different maps for different floors&period; By default&comma; a level picker &lpar;floor picker&rpar; appears near the center right-hand edge of the screen when the user is viewing an <a href&equals;"https&colon;&sol;&sol;developers&period;google&period;com&sol;maps&sol;documentation&sol;android-sdk&sol;map&num;indoor&lowbar;maps">indoor map<&sol;a>&period; You can disable or enable the level picker control by calling <strong><span style&equals;"color&colon; &num;008000&semi;"><em>setIndoorLevelPickerEnabled&lpar;&rpar;<&sol;em><&sol;span><&sol;strong><&sol;span><&sol;p>&NewLine;<pre>googleMap&period;getUiSettings&lpar;&rpar;&period;setIndoorLevelPickerEnabled&lpar;true&rpar;&semi;<&sol;pre>&NewLine;<h3><img class&equals;"alignnone size-full wp-image-1301" src&equals;"https&colon;&sol;&sol;c1ctech&period;com&sol;wp-content&sol;uploads&sol;2019&sol;11&sol;levelpicker&lowbar;img&period;png" alt&equals;"levelpicker&lowbar;img" width&equals;"320" height&equals;"480" &sol;><&sol;h3>&NewLine;<h3><span style&equals;"color&colon; &num;000080&semi;"><strong>Map Gesture<&sol;strong><&sol;span><&sol;h3>&NewLine;<p>A map created with the Maps SDK for Android supports the same gestures as the Google Maps application&period; However&comma; there might be situations where you want to disable certain gestures in order to preserve the state of the map&period;<&sol;p>&NewLine;<h4><strong><span style&equals;"color&colon; &num;0000ff&semi;">Zoom Gesture<&sol;span><&sol;strong><&sol;h4>&NewLine;<p>A user can change the zoom level of the camera&lpar;ie&period; zoom in&comma; zoom out&rpar;&period; If enabled&comma; users can either double tap&sol;two-finger tap or pinch to zoom the camera&period; If disabled&comma; these gestures have no effect&period; This setting doesn&&num;8217&semi;t affect the zoom buttons&period; You can disable zoom gestures by calling <strong><span style&equals;"color&colon; &num;008000&semi;"><em>setZoomGesturesEnabled&lpar;boolean&rpar;<&sol;em><&sol;span><&sol;strong> method<&sol;p>&NewLine;<pre>googleMap&period;getUiSettings&lpar;&rpar;&period;setZoomGesturesEnabled&lpar;false&rpar;&semi;<&sol;pre>&NewLine;<h4><strong><span style&equals;"color&colon; &num;0000ff&semi;">Scroll Gesture<&sol;span><&sol;strong><&sol;h4>&NewLine;<p>A user can scroll &lpar;pan&rpar; around the map by dragging the map with their finger&period; You can disable scrolling by calling <strong><span style&equals;"color&colon; &num;008000&semi;"><em>setScrollGesturesEnabled&lpar;boolean&rpar;<&sol;em><&sol;span><&sol;strong> method<&sol;p>&NewLine;<pre>googleMap&period;getUiSettings&lpar;&rpar;&period;setScrollGesturesEnabled&lpar;false&rpar;&semi;<&sol;pre>&NewLine;<h4><strong><span style&equals;"color&colon; &num;0000ff&semi;">Tilt Gesture<&sol;span><&sol;strong><&sol;h4>&NewLine;<p>A user can tilt the map by placing two fingers on the map and moving them down or up together to increase or decrease the tilt angle respectively&period; You can disable tilt gestures by calling <strong><span style&equals;"color&colon; &num;008000&semi;"><em>setTiltGesturesEnabled&lpar;boolean&rpar;<&sol;em><&sol;span><&sol;strong> method<&sol;p>&NewLine;<pre>googleMap&period;getUiSettings&lpar;&rpar;&period;setTiltGesturesEnabled&lpar;false&rpar;&semi;<&sol;pre>&NewLine;<h4><strong><span style&equals;"color&colon; &num;0000ff&semi;">Rotate Gesture<&sol;span><&sol;strong><&sol;h4>&NewLine;<p>A user can rotate the map by placing two fingers on the map and applying a rotate motion&period; You can disable rotation by calling <strong><span style&equals;"color&colon; &num;008000&semi;"><em>setRotateGesturesEnabled&lpar;boolean&rpar;<&sol;em> <&sol;span><&sol;strong>method<&sol;p>&NewLine;<pre>googleMap&period;getUiSettings&lpar;&rpar;&period;setRotateGesturesEnabled&lpar;false&rpar;&semi;<&sol;pre>&NewLine;<h3><&sol;h3>&NewLine;<h3><strong><span style&equals;"color&colon; &num;000080&semi;">Moving Camera to a Location with animation<&sol;span><&sol;strong><&sol;h3>&NewLine;<p>You may want to move the camera to a particular position&period; Google maps provide a set of functions to achieve this&period;<&sol;p>&NewLine;<pre>CameraPosition cameraPosition &equals; new CameraPosition&period;Builder&lpar;&rpar;&period;target&lpar;&NewLine; new LatLng&lpar;12&period;9716&comma; 77&period;5946&rpar;&rpar;&period;zoom&lpar;12&rpar;&period;build&lpar;&rpar;&semi;&NewLine;&NewLine;googleMap&period;animateCamera&lpar;CameraUpdateFactory&period;newCameraPosition&lpar;cameraPosition&rpar;&rpar;&semi;<&sol;pre>&NewLine;<p>Although google maps provides a lot of other features&comma; I covered only basic topics in this tutorial&period; Remaining topics seem to be pretty much lengthy&comma; so I’ll post them as separate articles&period;&NewLine;

Exit mobile version