Ten Lessons I've Learned From Sdk File For Android

Sdk File For Android

Today, Google Maps is calmly one of the world’s best accepted mapping services, acceptance millions of users to plan their journeys, ascertain new places to visit, and get a aftertaste of what it’s absolutely like to airing about places they may acquire never alike visited.


Image Source: imgur.com


We’ve already looked at how you can use the Google Maps API to retrieve and affectation the user’s location, but this able API isn’t bound to afraid a pin in a map!

In this article, we’ll be attractive at some of the added appearance that are included in the Google Maps API. By the end of this article, you’ll apperceive how to:

Before we can apparatus any of these features, we charge to actualize a activity that displays a basal Google Maps fragment.

To get this bureaucracy out of the way as bound as possible, I’ll be appliance Android Studio’s ‘Google Maps Activity’ arrangement and breeding a alter API key, which is appropriate if your activity is activity to affectation any Google Maps content. Aloof be acquainted that alter API keys aren’t decidedly secure, so afore publishing an appliance you charge consistently accomplish a new API key based on your project’s absolution certificate.

If your activity refuses to compile, again accomplish abiding your development ambiance is up to date, by aperture the Android SDK Manager and installing any accessible updates – in accurate accomplish abiding you acquire the latest versions of Google Play Casework and Google Repository.

This is the bald minimum appropriate to affectation Google Maps content, so at this point you may appetite to booty this activity for a circuit by installing it on your concrete smartphone or tablet, or an AVD (Android Virtual Device). If you’re testing this activity on an AVD, again you’ll charge to use a arrangement angel that includes the Google APIs.

Currently this activity displays a map with a brand assuredly set to Sydney, Australia. This isn’t absolutely activity to wow your users, so let’s attending at a few altered means of authoritative this activity added interesting.

When you accommodate Google Maps agreeable in your application, you about affectation the user’s accepted area via a marker, but there’s affluence of scenarios area it’s added advantageous to affectation area as a artery address. For example, if you’re booking a auto the ancient way (i.e by calling the auto company) or alignment to accommodated a friend, again alive the artery you’re currently on is activity to be appealing useful!

While your users could assignment this out for themselves by zooming in on their area brand and attractive at the surrounding labels, you can accommodate a abundant bigger acquaintance by presenting this advice to them. This activity of converting a set of breadth and breadth ethics into a artery address, is accepted as about-face geocoding.

In this section, we’re activity to add a button to our appliance that, aback tapped, retrieves the device’s breadth and latitude, about-face geocodes these coordinates into an almost artery address, and again presents this advice to the user.

Let’s alpha with the accessible stuff, and amend our user interface. Aback you actualize a activity appliance the Google Maps Activity template, the activity_maps.xml book contains a SupportMapFragment that fills the absolute screen.

I’m activity to aggrandize on this blueprint to accommodate a ‘Get My Location’ button that, aback tapped, updates a TextView with the about-face geocoded data.

Next, ascertain the cord assets that we’ll be appliance throughout this project:


Image Source: imgur.com


The additional cord ability is a placeholder that contains the following:

You catechumen breadth and breadth ethics into a concrete abode appliance the getFromLocation() method, which allotment a account of Abode objects.

The akin of detail alternate by getFromLocation() will alter depending on the location. Sometimes about-face geocoding may acknowledgment a abounding address, appropriate bottomward to the abode number; sometimes it’ll acknowledgment the name of the abutting architecture – and occasionally it may acknowledgment no advice at all.

While the closing is unlikely, your appliance shouldn’t blast if it does appointment this scenario. Here, I’m creating a Cord aloof in case this app can’t bout the coordinates to any accepted address:

On accessories active Android 6.0 (API akin 23) and higher, applications charge to appeal permissions at runtime, and the user can again acquire or abjure anniversary request, on a permission-by-permission basis.

If the user denies a permission request, again you charge to acquaint the appulse this will acquire on your application. In this project, I’m activity to affectation the afterward argument as allotment of a toast:

When alive on your own Android projects, you may additionally appetite to attenuate or abolish genitalia of your appliance that await on the denied permission, for archetype removing items from menus, or “greying out” assertive UI controls.

Reverse geocoding requires an Internet connection, so accessible your project’s Manifest and add the Internet permission:

Since about-face geocoding uses the network, it has the abeyant to block Android’s capital thread. To abstain Appliance Not Responding (ANR) errors and appliance crashes, you charge accomplish the about-face geocoding operation off the capital thread. There’s assorted means of creating accomplishments threads, but I’m activity to use an AsyncTask.

Create a new Java chic (I’m allotment abundance ReverseGeo) and apparatus the AsyncTask:

Next, we charge to apparatus ReverseGeo in our project’s automatically-generated MapsActivity class, and again override the onTaskComplete() method. I’m additionally implementing the onClickListener so our appliance can acknowledge to the user borer the ‘Get My Location’ button.

Let’s put this appliance to the test:


Image Source: androidcentral.com


Since we’re requesting the ACCESS_FINE_LOCATION permission at runtime, we charge to analysis how our appliance handles rejection:

You should additionally analysis how your appliance functions aback it has admission to your location, but can’t bout the coordinates to any accepted address. If you’re appliance a concrete Android device, again you can analysis this book appliance a third affair app:

If you’re testing this activity on an AVD, again you can change the device’s coordinates appliance the band of buttons that arise alongside the emulator:

Any Google Maps agreeable you accommodate in your app will use the “normal” map appearance by absence – but “normal” isn’t the alone option!

The Google Maps API supports a few altered map styles:

To affectation annihilation added than a “normal” map, you’ll charge to use the setMapType method:

Alternatively, why not accord your users the abandon to about-face amid map styles?

In this section, we’re activity to add a dropdown card that allows your users to move amid the normal, hybrid, area and accessory map styles, with ease.

Start by creating a card resource:

Open your project’s strings.xml book and ascertain all the card labels:

Next, you’ll charge to apparatus the card in your MapsActivity. To accomplish this activity clearer, I’ve removed all geocoding-specific cipher from this Activity.

Install the adapted appliance on your concrete Android accessory or AVD, accessible the menu, and analysis all the altered map styles.


Image Source: theopentutorials.com


Even analytical the aforementioned area beyond assorted map styles can’t absolutely analyze to the acquaintance of exploring that area from a first-person angle – which is area Artery Appearance comes in.

In this final section, I’ll appearance you how to accommodate a actual faculty of what a area is absolutely like, by amalgam Artery Appearance into our application.

Let’s alpha by afterlight our layout:

Next, I’m activity to actualize a StreetViewActivity, area I’ll apparatus the Artery Appearance service. Aback you accommodate a Artery Appearance panorama in your application, all the accepted Artery Appearance accomplishments are included by default, which is why the afterward cipher doesn’t accommodate any chiral implementations of animadversion and zooming gestures, or abyssal to adjoining panoramas, as you already get all this functionality for free!

Since I’m announcement the Artery Appearance panorama central an Android View, I’m appliance StreetViewPanoramaView, which is a bracket of the Appearance class. To affectation a panorama central a Fragment, you’d use StreetViewPanoramaFragment instead.

Don’t balloon to add the StreetViewActivity to your Manifest:

Finally, we charge to apparatus launchStreetView in our MapsActivity, so that android:onClick=”launchStreetView” triggers the StreetViewActivity class:

Install this activity on your Android device, and accord the ‘Street View’ button a tap. Your appliance should acknowledge by ablution a new Activity announcement a 360 amount panorama of the London Eye.

In this article, we explored a few means of acceptable your app’s Google Maps content, by abacus abutment for Artery View, assorted map styles, and about-face geocoding – but these are still aloof a few of the appearance that the Google Maps API has to offer.

What Google Maps appearance acquire you acclimated in your own projects? Let us apperceive in the comments below!

Sdk File For Android

Image Source: file-extensions.org



Image Source: tech-recipes.com



Image Source: tech-recipes.com


Posting Komentar