Tuesday 3 March 2015

How To Add Custom Marker, My Location, Views & Zoom Controls on your Map Application using Android Studio

How To Add Custom Marker, My Location, Views & Zoom Controls on your Map Application using Android Studio

Requirements
***Android studio
***map application project
***checking SDK files

Note:

Android studio blog here
create map application project here

"Internet connection should be connect when you build your applictaion"

Simple Steps

1. open your project on your android studio

Note: Already map application created by another blog.



2.Checking SDK files

Tools--->SDK manager

Goto extras files like "repository, library, all play services, drivers".



NOTE: All Extras files should must be download with complete updates

3. open main activity.java file




4. Goto top of the page

You see the "import ..."

Click the import you will see the list of imports




4. Add the some other imports

import android.content.Context;
import android.location.Criteria;
import android.location.Location;

import android.location.LocationManager;
import com.google.android.gms.maps.CameraUpdateFactory;

5. Goto down of page

You see the "private void setUpMap()"
Already some code there...

Put on the code below in "private void setUpMap()"

         mMap.setMyLocationEnabled(true); 
  
         LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); 
   
         Criteria criteria = new Criteria(); 
  
         String provider = locationManager.getBestProvider(criteria, true); 
  
   
         Location myLocation = locationManager.getLastKnownLocation(provider); 
  
         mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL); 

         double latitude = myLocation.getLatitude(); 

         double longitude = myLocation.getLongitude(); 

         LatLng latLng = new LatLng(latitude, longitude); 

         mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng)); 
  


         mMap.animateCamera(CameraUpdateFactory.zoomTo(14));


You will get some yellow marker warnings. Dont worry about that.

Now you can run the application and see map and my location zoom controls.




6. Change views on the map


mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL); 


You see the code on above codes & just change to

If u want satellite view copy and replace the code:


mMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
If u want terrain view copy and replace the code:
mMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN);

Results:
   
NORMAL                  SATELLITE                TERRAIN



7. Add permissions on your "Androidmanifest.xml"





Double click "Androidmanifest.xml"






Add the code on "Androidmanifest.xml"

<permission
        android:name="com.example.dell.myapplication.permission.MAPS_RECEIVE"
        android:protectionLevel="signature"/>

    <uses-permission android:name="com.example.dell.myapplication.permission.MAPS_RECEIVE"/>

    <uses-feature
        android:glEsVersion="0x00020000"

        android:required="true"/>


NOTE: i show you on my application package name. so you will need to change your package name in manifest code. my package name is"com.example.dell.myapplication". so you should change, its important.


DOWNLOAD: SOURCE CODE: CLICK here



How to Create Simple Maps Application using Android Studio with API Key Displaying on My Location & Zoom Controls

How to Create Simple Maps Application using Android Studio with API Key Displaying on My Location & Zoom Controls

MY Youtube Video



Requirements
***Android studio
***Android API Key

Simple Steps:

1. Open your Android studio

NOTE: if you dont have android studio please check my another blog here


2. Click "Start a new Android studio project"


3. Type your name of map application and package name  & click next


4. Select minimum SDK on API 17 & Slick Next


5. Select "Google Maps Activity" & Click Next


6. Put on maps activity name & Click Finish


wait for your project complete loading & gradle build

7. Create a Android API Key 

Copy the console link on your project it will go & register client key. console link like "https://console.developers.google.com/flows/enableapi?apiid=maps_android_backend&keyType=CLIENT_SIDE_ANDROID&r=A0:8E:99:A3:D1:06:51:88:1C:CA:D8:30:9E:EA:4A:62:A9:13:4D:77%3Bcom.example.dell.myapplication"

NOTE: i post my console application, but you will see the http console link on your application "google_maps_api.xml"


 Now google login & and select your API project


select API project with number


it will show like


copy the API Key in your package name as by show, it show like "AIzaSyAk2BHeNM77AOFaY2kBzJrstybIPTNw1NM"

copy the API Key and paste your "google_maps_api.xml" on show "YOUR _KEY_HERE"


8. Create a AVD

 Tools-->Android-->AVD manager



you will see some emulator on your devices. 

Click --> create new device 


select Nexus 4 -> click Next


Select Lollipo API21 (Google API) x64 image file

Note: if u have 64 bit system select 64 bit, or 32bit choose that.but google API is must.

Now choose as you created one Nexus 4 x64 Google API , you select and run Nexus 4 API which you create, now you can see pop up at similar emulator like mobile device.


wait for till loading is completing, it il take long time. 



8. Now build & Run your application


9. Click Run

Run-> Run
 you will see gradle build task. after completing gradle task without error ,the application will run on emulator or a device.


  
You can zoom using touch & drag zooming



Note: this is result of your application.. simple map application.
you can modify the "views , my location, zoom controls, sattelite view" by the changing java code in your project. if u want to see that, go to my next blog here
CLICK TO NEXT BLOG

Install & Configure Android Studio with SDK AVD on Windows 7

Installing Android Studio with SDK AVD Manager on Windows 7

Requirements:
***Android Studio
***Java Development Kit (JDK)

***(.NET) Frame work

Simple 10 Steps:

1.Download Android Studio Link here


2.Download Java Development Kit (JDK 7u75) Link here


3. Download .NET Framework here


4.  Install .NET Framework

   NOTE: Keep your internet connection fast and connected , Its very important.after you complete install close it.

5. Install Java Development Kit JDK 7u75

     Install JDK correctly, becoz its very important to run android into java environment on windows series. so dont forget to install.

6. Set Environment Variables on windows

    Computer -> Right Click ->Properties -> Advanced System Settings -> 

Click Environment Variables -> Below System Variables -> click NEW...


You will see the window


PUT values
Variable name:    JAVA_HOME
Variable value:    C:\Program Files\Java\jdk1.7.0_75\bin


Note: Variable value is your JDK installation path (bin) Directory.. i post only my installation directly but yours is varied because your java setup version & 32bit or 64bit may be changed or not..

Click  OK to complete.


7. Install Android Studio NOW..

   Note:    You will see some other pop up , just post my inbox  & i will guide you.


8. After completing Installing android studio you will turn on..




You success fully installed Android studio successfully..!

9. Configure SDK & AVD

     SDK Software Development Kit & AVD Android Virtual Monitor
    
     Click Configure on your Android Studio
     Click configure --> SDK Manager


Select and Tick to Download
Tools--> Android Build Tools
Click install packages after completing fill downloading tools. 


Click extras library , services, drivers and install packages wait for completing downloads.
Now you Configure SDK succesfully..

NOTE: You can have speed internet connection then only download API files ,Tools, libraries. if u r a beginner in android development you enough to run android studio but future uses is only you have update SDK fully is best.


API is Application Programming interface it is based on you android versions like Gingerbread(2.3.6), Icecreamsandwitch(4.0), Jellybean(4.1), Lollipop(5.0).  So which plat-form you need to create ,at the same time you need to update your API platform tools & files.


10. CREATE AVD Emulators

Android Virtual Device is a emulator to run and check your application as you created. its show as same of you android mobile interface with buttons. its has open only android application development window in android studio software.

NOTE: Past some other months Android studio version have some other own AVD's so you don't to create emulator. if u want i guide you..