অবস্থান ডেটা

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

কোড নমুনা

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

কোটলিন

জাভা

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

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

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

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

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

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

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

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

আপনার অ্যাপের কাজ করার জন্য যদি আনুমানিক অবস্থানের প্রয়োজন হয়, তাহলে আপনার অ্যাপের ম্যানিফেস্ট ফাইলে 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>

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

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

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

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

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

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

নিম্নলিখিত কোড নমুনা আমার অবস্থান স্তর সক্রিয় করার আগে AndroidX লাইব্রেরি ব্যবহার করে অনুমতি পরীক্ষা করে। এটি সাপোর্ট লাইব্রেরি থেকে 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.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import androidx.core.app.ActivityCompat.OnRequestPermissionsResultCallback
import androidx.core.content.ContextCompat
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 : AppCompatActivity(),
    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)
    }

    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 AppCompatActivity
    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(R.layout.my_location_demo);

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

    @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() কলব্যাক পাবে।
  • ব্যবহারকারী আমার অবস্থান নীল বিন্দুতে ক্লিক করলে, আপনার অ্যাপ GoogleMap.OnMyLocationClickListener থেকে একটি onMyLocationClick() কলব্যাক পাবে।

Google Play পরিষেবার অবস্থান API

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

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

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