অবস্থান ডেটা

মোবাইল অ্যাপ্লিকেশনের একটি অনন্য বৈশিষ্ট্য হল অবস্থান সচেতনতা। মোবাইল ব্যবহারকারীরা তাদের ডিভাইসগুলি সর্বত্র তাদের সাথে নিয়ে যান এবং আপনার অ্যাপে অবস্থান সচেতনতা যুক্ত করলে ব্যবহারকারীরা আরও প্রাসঙ্গিক অভিজ্ঞতা পাবেন।

কোড নমুনা

GitHub-এর ApiDemos সংগ্রহস্থলে এমন নমুনা রয়েছে যা মানচিত্রে অবস্থানের ব্যবহার প্রদর্শন করে:

কোটলিন

জাভা

অবস্থানের তথ্য নিয়ে কাজ করা

একটি অ্যান্ড্রয়েড ডিভাইসে উপলব্ধ অবস্থানের ডেটাতে ডিভাইসের বর্তমান অবস্থান অন্তর্ভুক্ত থাকে — প্রযুক্তির সংমিশ্রণ ব্যবহার করে নির্দিষ্ট করা হয় — চলাচলের দিক এবং পদ্ধতি, এবং ডিভাইসটি পূর্বনির্ধারিত ভৌগোলিক সীমানা, অথবা জিওফেন্স পেরিয়ে গেছে কিনা। আপনার অ্যাপ্লিকেশনের চাহিদার উপর নির্ভর করে, আপনি অবস্থানের ডেটা নিয়ে কাজ করার বিভিন্ন উপায়ের মধ্যে একটি বেছে নিতে পারেন:

  • আমার অবস্থান স্তরটি মানচিত্রে কোনও ডিভাইসের অবস্থান প্রদর্শনের একটি সহজ উপায় প্রদান করে। এটি কোনও ডেটা প্রদান করে না।
  • অবস্থান ডেটার জন্য সমস্ত প্রোগ্রাম্যাটিক অনুরোধের জন্য Google Play পরিষেবা অবস্থান API সুপারিশ করা হয়।
  • LocationSource ইন্টারফেস আপনাকে একটি কাস্টম লোকেশন প্রোভাইডার প্রদান করতে দেয়।

অবস্থানের অনুমতি

যদি আপনার অ্যাপের ব্যবহারকারীর অবস্থান অ্যাক্সেস করার প্রয়োজন হয়, তাহলে আপনার অ্যাপে প্রাসঙ্গিক Android অবস্থানের অনুমতি যোগ করে অনুমতির জন্য অনুরোধ করতে হবে।

অ্যান্ড্রয়েড দুটি অবস্থানের অনুমতি প্রদান করে: ACCESS_COARSE_LOCATION এবং ACCESS_FINE_LOCATION । আপনার নির্বাচিত অনুমতি API দ্বারা প্রদত্ত অবস্থানের নির্ভুলতা নির্ধারণ করে।

  • android.permission.ACCESS_COARSE_LOCATION – API কে ডিভাইসের আনুমানিক অবস্থান ফেরত দেওয়ার অনুমতি দেয়। অনুমতিটি অবস্থান পরিষেবাগুলি থেকে ডিভাইসের অবস্থানের একটি অনুমান প্রদান করে, যেমনটি আনুমানিক অবস্থান নির্ভুলতা সম্পর্কে ডকুমেন্টেশনে বর্ণিত হয়েছে।
  • android.permission.ACCESS_FINE_LOCATION – API-কে গ্লোবাল পজিশনিং সিস্টেম (GPS) এবং ওয়াইফাই এবং মোবাইল সেল ডেটা সহ উপলব্ধ অবস্থান প্রদানকারীদের কাছ থেকে যতটা সম্ভব সুনির্দিষ্ট অবস্থান নির্ধারণ করতে দেয়।

অ্যাপ ম্যানিফেস্টে অনুমতিগুলি যোগ করুন

যদি আপনার অ্যাপটি কাজ করার জন্য শুধুমাত্র আনুমানিক অবস্থানের প্রয়োজন হয়, তাহলে আপনার অ্যাপের ম্যানিফেস্ট ফাইলে ACCESS_COARSE_LOCATION অনুমতি যোগ করুন:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myapp" >
  ...
  <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
  ...
</manifest>

তবে, যদি সুনির্দিষ্ট অবস্থানের প্রয়োজন হয়, তাহলে আপনার অ্যাপের ম্যানিফেস্ট ফাইলে ACCESS_COARSE_LOCATION এবং ACCESS_FINE_LOCATION উভয় অনুমতি যোগ করুন:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myapp" >
  ...
  <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
  ...
</manifest>

রানটাইম অনুমতির অনুরোধ করুন

অ্যান্ড্রয়েড ৬.০ (মার্শম্যালো) অনুমতি পরিচালনার জন্য একটি নতুন মডেল প্রবর্তন করেছে, যা ব্যবহারকারীদের জন্য অ্যাপ ইনস্টল এবং আপগ্রেড করার প্রক্রিয়াটিকে সহজ করে তোলে। যদি আপনার অ্যাপটি API লেভেল ২৩ বা তার পরবর্তী লেভেলের জন্য লক্ষ্য করে, তাহলে আপনি নতুন অনুমতি মডেলটি ব্যবহার করতে পারেন।

যদি আপনার অ্যাপটি নতুন অনুমতি মডেল সমর্থন করে এবং ডিভাইসটি অ্যান্ড্রয়েড 6.0 (মার্শম্যালো) বা তার পরবর্তী সংস্করণে চলে, তাহলে ব্যবহারকারীকে অ্যাপটি ইনস্টল বা আপগ্রেড করার সময় কোনও অনুমতি দিতে হবে না। রানটাইমের সময় অ্যাপটির প্রয়োজনীয় অনুমতি আছে কিনা তা পরীক্ষা করে দেখতে হবে এবং যদি অনুমতি না থাকে তবে অনুরোধ করতে হবে। সিস্টেমটি ব্যবহারকারীকে অনুমতি চেয়ে একটি ডায়ালগ প্রদর্শন করবে।

সর্বোত্তম ব্যবহারকারীর অভিজ্ঞতার জন্য, প্রেক্ষাপটে অনুমতির জন্য অনুরোধ করা গুরুত্বপূর্ণ। যদি আপনার অ্যাপের কার্যকারিতার জন্য অবস্থান অপরিহার্য হয়, তাহলে অ্যাপ শুরু করার সময় আপনার অবস্থানের অনুমতির জন্য অনুরোধ করা উচিত। এটি করার একটি ভাল উপায় হল একটি উষ্ণ স্বাগত স্ক্রিন বা উইজার্ড যা ব্যবহারকারীদের অনুমতি কেন প্রয়োজন তা সম্পর্কে শিক্ষিত করে।

যদি অ্যাপটির কার্যকারিতার কিছু অংশের জন্যই অনুমতির প্রয়োজন হয়, তাহলে অ্যাপটি যখন অনুমতির প্রয়োজন এমন কাজটি করবে তখনই আপনার অবস্থানের অনুমতির জন্য অনুরোধ করা উচিত।

ব্যবহারকারী যখন অনুমতি না দেন, তখন অ্যাপটিকে অবশ্যই সুন্দরভাবে সেই পরিস্থিতি মোকাবেলা করতে হবে। উদাহরণস্বরূপ, যদি কোনও নির্দিষ্ট বৈশিষ্ট্যের জন্য অনুমতির প্রয়োজন হয়, তাহলে অ্যাপটি সেই বৈশিষ্ট্যটি অক্ষম করতে পারে। যদি অ্যাপটি কাজ করার জন্য অনুমতিটি অপরিহার্য হয়, তাহলে অ্যাপটি তার সমস্ত কার্যকারিতা অক্ষম করতে পারে এবং ব্যবহারকারীকে জানাতে পারে যে তাদের অনুমতি প্রদান করা প্রয়োজন।

নিম্নলিখিত কোড নমুনাটি My Location লেয়ার সক্রিয় করার আগে AndroidX লাইব্রেরি ব্যবহার করে অনুমতি পরীক্ষা করে। এরপর এটি Support লাইব্রেরি থেকে ActivityCompat.OnRequestPermissionsResultCallback বাস্তবায়নের মাধ্যমে অনুমতি অনুরোধের ফলাফল পরিচালনা করে:

কোটলিন

// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.example.kotlindemos

import android.Manifest
import android.annotation.SuppressLint
import android.content.pm.PackageManager
import android.location.Location
import android.os.Bundle
import android.view.View
import android.widget.Toast

import androidx.core.app.ActivityCompat
import androidx.core.app.ActivityCompat.OnRequestPermissionsResultCallback
import androidx.core.content.ContextCompat
import com.example.common_ui.R
import com.example.kotlindemos.PermissionUtils.PermissionDeniedDialog.Companion.newInstance
import com.example.kotlindemos.PermissionUtils.isPermissionGranted
import com.google.android.gms.maps.GoogleMap
import com.google.android.gms.maps.GoogleMap.OnMyLocationButtonClickListener
import com.google.android.gms.maps.GoogleMap.OnMyLocationClickListener
import com.google.android.gms.maps.OnMapReadyCallback
import com.google.android.gms.maps.SupportMapFragment

/**
 * This demo shows how GMS Location can be used to check for changes to the users location.  The
 * "My Location" button uses GMS Location to set the blue dot representing the users location.
 * Permission for [Manifest.permission.ACCESS_FINE_LOCATION] and [Manifest.permission.ACCESS_COARSE_LOCATION]
 * are requested at run time. If either permission is not granted, the Activity is finished with an error message.
 */
class MyLocationDemoActivity : SamplesBaseActivity(),
    OnMyLocationButtonClickListener,
    OnMyLocationClickListener, OnMapReadyCallback,
    OnRequestPermissionsResultCallback {
    /**
     * Flag indicating whether a requested permission has been denied after returning in
     * [.onRequestPermissionsResult].
     */
    private var permissionDenied = false
    private lateinit var map: GoogleMap
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.my_location_demo)
        val mapFragment =
            supportFragmentManager.findFragmentById(R.id.map) as SupportMapFragment?
        mapFragment?.getMapAsync(this)
        applyInsets(findViewById<View?>(R.id.map_container))
    }

    override fun onMapReady(googleMap: GoogleMap) {
        map = googleMap
        googleMap.setOnMyLocationButtonClickListener(this)
        googleMap.setOnMyLocationClickListener(this)
        enableMyLocation()
    }

    /**
     * Enables the My Location layer if the fine location permission has been granted.
     */
    @SuppressLint("MissingPermission")
    private fun enableMyLocation() {

        // 1. Check if permissions are granted, if so, enable the my location layer
        if (ContextCompat.checkSelfPermission(
                this,
                Manifest.permission.ACCESS_FINE_LOCATION
            ) == PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(
                this,
                Manifest.permission.ACCESS_COARSE_LOCATION
            ) == PackageManager.PERMISSION_GRANTED
        ) {
            map.isMyLocationEnabled = true
            return
        }

        // 2. If if a permission rationale dialog should be shown
        if (ActivityCompat.shouldShowRequestPermissionRationale(
                this,
                Manifest.permission.ACCESS_FINE_LOCATION
            ) || ActivityCompat.shouldShowRequestPermissionRationale(
                this,
                Manifest.permission.ACCESS_COARSE_LOCATION
            )
        ) {
            PermissionUtils.RationaleDialog.newInstance(
                LOCATION_PERMISSION_REQUEST_CODE, true
            ).show(supportFragmentManager, "dialog")
            return
        }

        // 3. Otherwise, request permission
        ActivityCompat.requestPermissions(
            this,
            arrayOf(
                Manifest.permission.ACCESS_FINE_LOCATION,
                Manifest.permission.ACCESS_COARSE_LOCATION
            ),
            LOCATION_PERMISSION_REQUEST_CODE
        )
    }

    override fun onMyLocationButtonClick(): Boolean {
        Toast.makeText(this, "MyLocation button clicked", Toast.LENGTH_SHORT)
            .show()
        // Return false so that we don't consume the event and the default behavior still occurs
        // (the camera animates to the user's current position).
        return false
    }

    override fun onMyLocationClick(location: Location) {
        Toast.makeText(this, "Current location:\n$location", Toast.LENGTH_LONG)
            .show()
    }

    override fun onRequestPermissionsResult(
        requestCode: Int,
        permissions: Array<String>,
        grantResults: IntArray
    ) {
        if (requestCode != LOCATION_PERMISSION_REQUEST_CODE) {
            super.onRequestPermissionsResult(
                requestCode,
                permissions,
                grantResults
            )
            return
        }

        if (isPermissionGranted(
                permissions,
                grantResults,
                Manifest.permission.ACCESS_FINE_LOCATION
            ) || isPermissionGranted(
                permissions,
                grantResults,
                Manifest.permission.ACCESS_COARSE_LOCATION
            )
        ) {
            // Enable the my location layer if the permission has been granted.
            enableMyLocation()
        } else {
            // Permission was denied. Display an error message
            // Display the missing permission error dialog when the fragments resume.
            permissionDenied = true
        }
    }

    override fun onResumeFragments() {
        super.onResumeFragments()
        if (permissionDenied) {
            // Permission was not granted, display error dialog.
            showMissingPermissionError()
            permissionDenied = false
        }
    }

    /**
     * Displays a dialog with error message explaining that the location permission is missing.
     */
    private fun showMissingPermissionError() {
        newInstance(true).show(supportFragmentManager, "dialog")
    }

    companion object {
        /**
         * Request code for location permission request.
         *
         * @see .onRequestPermissionsResult
         */
        private const val LOCATION_PERMISSION_REQUEST_CODE = 1
    }
}

জাভা

// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.


package com.example.mapdemo;

import android.Manifest.permission;
import android.annotation.SuppressLint;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.OnMyLocationButtonClickListener;
import com.google.android.gms.maps.GoogleMap.OnMyLocationClickListener;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;

import android.Manifest;
import android.content.pm.PackageManager;
import android.location.Location;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import android.widget.Toast;

/**
 * This demo shows how GMS Location can be used to check for changes to the users location.  The "My
 * Location" button uses GMS Location to set the blue dot representing the users location.
 * Permission for {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and {@link
 * android.Manifest.permission#ACCESS_COARSE_LOCATION} are requested at run time. If either
 * permission is not granted, the Activity is finished with an error message.
 */
public class MyLocationDemoActivity extends SamplesBaseActivity
    implements
    OnMyLocationButtonClickListener,
    OnMyLocationClickListener,
    OnMapReadyCallback,
    ActivityCompat.OnRequestPermissionsResultCallback {

    /**
     * Request code for location permission request.
     *
     * @see #onRequestPermissionsResult(int, String[], int[])
     */
    private static final int LOCATION_PERMISSION_REQUEST_CODE = 1;

    /**
     * Flag indicating whether a requested permission has been denied after returning in {@link
     * #onRequestPermissionsResult(int, String[], int[])}.
     */
    private boolean permissionDenied = false;

    private GoogleMap map;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(com.example.common_ui.R.layout.my_location_demo);

        SupportMapFragment mapFragment =
            (SupportMapFragment) getSupportFragmentManager().findFragmentById(com.example.common_ui.R.id.map);
        mapFragment.getMapAsync(this);
        applyInsets(findViewById(com.example.common_ui.R.id.map_container));
    }

    @Override
    public void onMapReady(@NonNull GoogleMap googleMap) {
        map = googleMap;
        map.setOnMyLocationButtonClickListener(this);
        map.setOnMyLocationClickListener(this);
        enableMyLocation();
    }

    /**
     * Enables the My Location layer if the fine location permission has been granted.
     */
    @SuppressLint("MissingPermission")
    private void enableMyLocation() {
        // 1. Check if permissions are granted, if so, enable the my location layer
        if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
            == PackageManager.PERMISSION_GRANTED
            || ContextCompat.checkSelfPermission(this, permission.ACCESS_COARSE_LOCATION)
            == PackageManager.PERMISSION_GRANTED) {
            map.setMyLocationEnabled(true);
            return;
        }

        // 2. Otherwise, request location permissions from the user.
        PermissionUtils.requestLocationPermissions(this, LOCATION_PERMISSION_REQUEST_CODE, true);
    }

    @Override
    public boolean onMyLocationButtonClick() {
        Toast.makeText(this, "MyLocation button clicked", Toast.LENGTH_SHORT).show();
        // Return false so that we don't consume the event and the default behavior still occurs
        // (the camera animates to the user's current position).
        return false;
    }

    @Override
    public void onMyLocationClick(@NonNull Location location) {
        Toast.makeText(this, "Current location:\n" + location, Toast.LENGTH_LONG).show();
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
        @NonNull int[] grantResults) {
        if (requestCode != LOCATION_PERMISSION_REQUEST_CODE) {
            super.onRequestPermissionsResult(requestCode, permissions, grantResults);
            return;
        }

        if (PermissionUtils.isPermissionGranted(permissions, grantResults,
            Manifest.permission.ACCESS_FINE_LOCATION) || PermissionUtils
            .isPermissionGranted(permissions, grantResults,
                Manifest.permission.ACCESS_COARSE_LOCATION)) {
            // Enable the my location layer if the permission has been granted.
            enableMyLocation();
        } else {
            // Permission was denied. Display an error message
            // Display the missing permission error dialog when the fragments resume.
            permissionDenied = true;
        }
    }

    @Override
    protected void onResumeFragments() {
        super.onResumeFragments();
        if (permissionDenied) {
            // Permission was not granted, display error dialog.
            showMissingPermissionError();
            permissionDenied = false;
        }
    }

    /**
     * Displays a dialog with error message explaining that the location permission is missing.
     */
    private void showMissingPermissionError() {
        PermissionUtils.PermissionDeniedDialog
            .newInstance(true).show(getSupportFragmentManager(), "dialog");
    }

}

আমার অবস্থান স্তর

আপনি আমার অবস্থান স্তর এবং আমার অবস্থান বোতাম ব্যবহার করে আপনার ব্যবহারকারীকে মানচিত্রে তাদের বর্তমান অবস্থান দেখাতে পারেন। মানচিত্রে আমার অবস্থান স্তর সক্ষম করতে mMap.setMyLocationEnabled() এ কল করুন।

নিম্নলিখিত নমুনাটি আমার অবস্থান স্তরের একটি সহজ ব্যবহার দেখায়:

কোটলিন

// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.maps.example.kotlin

import android.annotation.SuppressLint
import android.location.Location
import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.google.android.gms.maps.GoogleMap
import com.google.android.gms.maps.GoogleMap.OnMyLocationButtonClickListener
import com.google.android.gms.maps.GoogleMap.OnMyLocationClickListener
import com.google.android.gms.maps.OnMapReadyCallback
import com.google.android.gms.maps.SupportMapFragment
import com.google.maps.example.R

internal class MyLocationLayerActivity : AppCompatActivity(),
    OnMyLocationButtonClickListener,
    OnMyLocationClickListener,
    OnMapReadyCallback {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_my_location)
        val mapFragment =
            supportFragmentManager.findFragmentById(R.id.map) as SupportMapFragment
        mapFragment.getMapAsync(this)
    }

    @SuppressLint("MissingPermission")
    override fun onMapReady(map: GoogleMap) {
        // TODO: Before enabling the My Location layer, you must request
        // location permission from the user. This sample does not include
        // a request for location permission.
        map.isMyLocationEnabled = true
        map.setOnMyLocationButtonClickListener(this)
        map.setOnMyLocationClickListener(this)
    }

    override fun onMyLocationClick(location: Location) {
        Toast.makeText(this, "Current location:\n$location", Toast.LENGTH_LONG)
            .show()
    }

    override fun onMyLocationButtonClick(): Boolean {
        Toast.makeText(this, "MyLocation button clicked", Toast.LENGTH_SHORT)
            .show()
        // Return false so that we don't consume the event and the default behavior still occurs
        // (the camera animates to the user's current position).
        return false
    }
}


      

জাভা

// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.maps.example;

import android.annotation.SuppressLint;
import android.location.Location;
import android.os.Bundle;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;

class MyLocationLayerActivity extends AppCompatActivity
    implements GoogleMap.OnMyLocationButtonClickListener,
    GoogleMap.OnMyLocationClickListener,
    OnMapReadyCallback {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_location);

        SupportMapFragment mapFragment =
            (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);
    }

    @SuppressLint("MissingPermission")
    @Override
    public void onMapReady(GoogleMap map) {
        // TODO: Before enabling the My Location layer, you must request
        // location permission from the user. This sample does not include
        // a request for location permission.
        map.setMyLocationEnabled(true);
        map.setOnMyLocationButtonClickListener(this);
        map.setOnMyLocationClickListener(this);
    }

    @Override
    public void onMyLocationClick(@NonNull Location location) {
        Toast.makeText(this, "Current location:\n" + location, Toast.LENGTH_LONG)
            .show();
    }

    @Override
    public boolean onMyLocationButtonClick() {
        Toast.makeText(this, "MyLocation button clicked", Toast.LENGTH_SHORT)
            .show();
        // Return false so that we don't consume the event and the default behavior still occurs
        // (the camera animates to the user's current position).
        return false;
    }
}


      

যখন "আমার অবস্থান" স্তরটি সক্রিয় থাকে, তখন মানচিত্রের উপরের ডানদিকে "আমার অবস্থান" বোতামটি প্রদর্শিত হয়। যখন কোনও ব্যবহারকারী বোতামটি ক্লিক করেন, তখন ক্যামেরাটি ডিভাইসের বর্তমান অবস্থানের উপর মানচিত্রটিকে কেন্দ্র করে, যদি এটি জানা থাকে। ডিভাইসটি স্থির থাকলে মানচিত্রে একটি ছোট নীল বিন্দু দ্বারা অবস্থানটি নির্দেশিত হয়, অথবা ডিভাইসটি চলমান থাকলে শেভ্রন হিসাবে।

নিচের স্ক্রিনশটে উপরে ডানদিকে "আমার অবস্থান" বোতামটি এবং মানচিত্রের কেন্দ্রে "আমার অবস্থান" নীল বিন্দুটি দেখানো হয়েছে:

আপনি UiSettings.setMyLocationButtonEnabled(false) কল করে আমার অবস্থান বোতামটি প্রদর্শিত হওয়া থেকে বিরত রাখতে পারেন।

আপনার অ্যাপ নিম্নলিখিত ইভেন্টগুলিতে সাড়া দিতে পারে:

  • যদি ব্যবহারকারী আমার অবস্থান বোতামে ক্লিক করেন, তাহলে আপনার অ্যাপটি GoogleMap.OnMyLocationButtonClickListener থেকে একটি onMyLocationButtonClick() কলব্যাক পাবে।
  • যদি ব্যবহারকারী My Location নীল বিন্দুতে ক্লিক করেন, তাহলে আপনার অ্যাপটি GoogleMap.OnMyLocationClickListener থেকে একটি onMyLocationClick() কলব্যাক পাবে।

গুগল প্লে সার্ভিসেস লোকেশন এপিআই

আপনার অ্যান্ড্রয়েড অ্যাপ্লিকেশনে অবস্থান সচেতনতা যোগ করার জন্য Google Play পরিষেবা অবস্থান API হল পছন্দের পদ্ধতি। এতে এমন কার্যকারিতা রয়েছে যা আপনাকে এগুলি করতে দেয়:

  • ডিভাইসের অবস্থান নির্ধারণ করুন।
  • অবস্থান পরিবর্তনের জন্য শুনুন।
  • ডিভাইসটি চলমান থাকলে পরিবহনের ধরণ নির্ধারণ করুন।
  • পূর্বনির্ধারিত ভৌগোলিক অঞ্চল তৈরি এবং নিরীক্ষণ করুন, যা জিওফেন্স নামে পরিচিত।

লোকেশন এপিআই আপনার জন্য বিদ্যুৎ সাশ্রয়ী, লোকেশন-সচেতন অ্যাপ্লিকেশন তৈরি করা সহজ করে তোলে। অ্যান্ড্রয়েডের জন্য ম্যাপস এসডিকে-র মতো, লোকেশন এপিআই গুগল প্লে সার্ভিসেস এসডিকে-র অংশ হিসাবে বিতরণ করা হয়। লোকেশন এপিআই সম্পর্কে আরও তথ্যের জন্য, দয়া করে অ্যান্ড্রয়েড প্রশিক্ষণ ক্লাস মেকিং ইওর অ্যাপ লোকেশন অ্যাওয়্যার অথবা লোকেশন এপিআই রেফারেন্স দেখুন। কোড উদাহরণগুলি গুগল প্লে সার্ভিসেস এসডিকে-র অংশ হিসাবে অন্তর্ভুক্ত করা হয়েছে।