{"id":23546,"date":"2015-07-28T15:12:51","date_gmt":"2015-07-28T09:42:51","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=23546"},"modified":"2015-07-29T10:41:32","modified_gmt":"2015-07-29T05:11:32","slug":"integrating-google-maps-in-android","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/integrating-google-maps-in-android\/","title":{"rendered":"Integrating google maps in android."},"content":{"rendered":"<p>Following blog talks about integrating Google Map into your <a title=\"Android App Development\" href=\"http:\/\/www.tothenew.com\/mobile-android-application-development-services\">Android applications<\/a> &#8211;<\/p>\n<p>It&#8217;s easy to integrate google maps in android app, Infact the only thing you need is an API KEY from google and you can have it in few steps as follows -:<\/p>\n<ol>\n<li>SignIn to your Google Account and Open google developer console by visting <a title=\"google developer console\" href=\"https:\/\/console.developers.google.com.\">https:\/\/console.developers.google.com.<\/a><\/li>\n<li>\u00a0Create a new Project.<\/li>\n<\/ol>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-23929\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/07\/Screenshot-from-2015-07-27-140410.png\" alt=\"Screenshot from 2015-07-27 14:04:10\" width=\"825\" height=\"557\" \/><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-23931\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/07\/Screenshot-from-2015-07-27-140606.png\" alt=\"Screenshot from 2015-07-27 14:06:06\" width=\"490\" height=\"211\" \/><\/p>\n<p>3.\u00a0 Open Project and select Api &amp; Auth section.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-23932\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/07\/Screenshot-from-2015-07-27-140637.png\" alt=\"Screenshot from 2015-07-27 14:06:37\" width=\"1137\" height=\"670\" \/><\/p>\n<p>4.\u00a0 Inside Api &amp; Auth section select Api, and enable the google map Api.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-23933\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/07\/Screenshot-from-2015-07-27-140651.png\" alt=\"Screenshot from 2015-07-27 14:06:51\" width=\"668\" height=\"418\" \/><\/p>\n<p>5.\u00a0 Next move to credentials section and create an android key.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-23935\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/07\/Screenshot-from-2015-07-27-140724.png\" alt=\"Screenshot from 2015-07-27 14:07:24\" width=\"906\" height=\"496\" \/><\/p>\n<p><em> To generate the key You need to have SHA1 fingerprint and package name of your app.To get SHA1 fingerprint run below command on terminal.<\/em><\/p>\n<p>keytool -list -v -keystore keystore_path.<\/p>\n<p><strong><em>But Before that You need to create keystore of your app(so that you can have map on signed apk also).<\/em><\/strong><\/p>\n<p><strong><em>Using android studio, you can create it by selecting build -&gt; generate singed apk -&gt; create new keystore by giving keystore path,password and alias name.<\/em><\/strong><\/p>\n<p><em>Put keystore path and run above command and enter keystore password, here you will get SHA1 Key keep that key.<\/em><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-23963\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/07\/Screenshot-from-2015-07-27-15_02_30.png\" alt=\"Screenshot from 2015-07-27 15_02_30\" width=\"826\" height=\"298\" \/><\/p>\n<p><strong><em>Note : For debugging you can use debug keystore which is created the first time you build your project. By default, it is stored in the same directory as your Android Virtual Device (AVD) files. <\/em><\/strong><\/p>\n<p>6.\u00a0 Now get back to developer console and create android key by putting SHA1 fingerPrint\u00a0 followed by application package name.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-23974\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/07\/Screenshot-from-2015-07-27-155709.png\" alt=\"Screenshot from 2015-07-27 15:57:09\" width=\"653\" height=\"457\" \/><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-23975\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/07\/Screenshot-from-2015-07-27-155727.png\" alt=\"Screenshot from 2015-07-27 15:57:27\" width=\"1100\" height=\"511\" \/><\/p>\n<p>Now Make a new android project and create a MapActivity.<br \/>\nOpen Manifest File and put the following permissions and generated API KEY.<\/p>\n<p>[sourcecode language=&#8221;java&#8221;]<\/p>\n<p>uses-permission android:name=&quot;android.permission.ACCESS_NETWORK_STATE&quot;<br \/>\nuses-permission android:name=&quot;android.permission.INTERNET&quot;<br \/>\nuses-permission android:name=&quot;com.google.android.providers.gsf.permission.READ_GSERVICES&quot;<br \/>\nuses-permission android:name=&quot;android.permission.WRITE_EXTERNAL_STORAGE&quot;<\/p>\n<p>&lt;Application&gt;<br \/>\nmeta-data<br \/>\nandroid:name=&quot;com.google.android.maps.v2.API_KEY&quot;<br \/>\nandroid:value=&quot;put console Api key here&quot;<br \/>\n&lt;\/Application&gt;<\/p>\n<p>[\/sourcecode]<\/p>\n<p>To show Current Location on your map call requestLocationUpdates() as &#8211;<\/p>\n<p>[sourcecode language=&#8221;java&#8221;]<br \/>\nLocationManager locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);<br \/>\nlocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, new LocationListener() {<br \/>\n    @Override<br \/>\n    public void onLocationChanged(Location location) {<br \/>\n        mMap.addMarker(new MarkerOptions().position(new LatLng(location.getLatitude(), location.getLongitude())).title(&quot;you are here&quot;));<\/p>\n<p>        LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());<br \/>\n        CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(latLng, 10);<br \/>\n        mMap.animateCamera(cameraUpdate);<br \/>\n    }<\/p>\n<p>    @Override<br \/>\n    public void onStatusChanged(String provider, int status, Bundle extras) {<\/p>\n<p>    }<\/p>\n<p>    @Override<br \/>\n    public void onProviderEnabled(String provider) {<\/p>\n<p>    }<\/p>\n<p>    @Override<br \/>\n    public void onProviderDisabled(String provider) {<\/p>\n<p>    }<br \/>\n});<br \/>\n[\/sourcecode]<\/p>\n<p>You can also set the type of the MAP. There are four different types of map &#8211; Normal,Hybrid,Satellite and terrain and each give different view. You can use them as below.<\/p>\n<p>[sourcecode language=&#8221;java&#8221;]<br \/>\ngoogleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);<br \/>\ngoogleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);<br \/>\ngoogleMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);<br \/>\ngoogleMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN);<br \/>\n[\/sourcecode]<\/p>\n<p>Enable the zoom gesture in map as.<\/p>\n<p>[sourcecode language=&#8221;java&#8221;]<br \/>\ngoogleMap.getUiSettings().setZoomGesturesEnabled(true);<br \/>\n[\/sourcecode]<\/p>\n<p>run project to get map.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-24164\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/07\/device-2015-07-28-143005.png\" alt=\"device-2015-07-28-143005\" width=\"540\" height=\"960\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Following blog talks about integrating Google Map into your Android applications &#8211; It&#8217;s easy to integrate google maps in android app, Infact the only thing you need is an API KEY from google and you can have it in few steps as follows -: SignIn to your Google Account and Open google developer console by [&hellip;]<\/p>\n","protected":false},"author":156,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":1},"categories":[518],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/23546"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/156"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=23546"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/23546\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=23546"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=23546"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=23546"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}