Monday, 4 September 2017

Open Google Map in Your Application in Android

About Example:- Here is the example that "How to open Google Maps in Android Application By using Coding"

Basic Requirement:-
1. MainActivity.java
2.activity_main.xml

Steps are:-
Step 1: Add a new project and open activity_main.xml and write following code:-
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"   
 xmlns:app="http://schemas.android.com/apk/res-auto"   
 xmlns:tools="http://schemas.android.com/tools"   
 android:layout_width="match_parent"   
 android:layout_height="match_parent"   
 android:background="#33B8FF"   
 android:orientation="vertical"   
 android:gravity="center"    
tools:context="com.example.supriyabharti.launchgooglemapexmp.MainActivity">

    <Button        
android:id="@+id/btn_map"        
android:layout_width="wrap_content"        
android:layout_height="wrap_content"        
android:text="Show Map"        
android:layout_marginBottom="20dp"
        android:textColor="#fff"         />
    

</LinearLayout>

Step 2:- Open your MainActivity.java and write following code:-

package com.example.supriyabharti.launchgooglemapexmp;

import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {
    Button btn;
    

    @Override   
 protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        btn=(Button)findViewById(R.id.btn_map);
        
        btn.setOnClickListener(new View.OnClickListener() {
            @Override   
         public void onClick(View view) {
                Intent i=new Intent(Intent.ACTION_VIEW);
                i.setData(Uri.parse("geo:47.4925,19.0513"));
                Intent c=Intent.createChooser(i,"Launch Maps");
                startActivity(c);
            }
        });
    }
}


Step 3: Open Manifests and take user permission :-


    <uses-permission android:name="android.permission.INTERNET">
</uses-permission>
Ouput will like:-

No comments:

Post a Comment