जगह की जानकारी का डेटा

मोबाइल ऐप्लिकेशन की खास सुविधाओं में से एक है जगह के बारे में जानकारी. मोबाइल उपयोगकर्ता अपने डिवाइसों को हर जगह अपने साथ लाते हैं और अपने ऐप्लिकेशन में स्थान जागरूकता जोड़ने से उपयोगकर्ताओं को प्रासंगिक अनुभव मिलता है.

कोड सैंपल

GitHub पर ApiDemos रिपॉज़िटरी में ऐसे सैंपल शामिल हैं जो मैप पर जगह की जानकारी के इस्तेमाल को दिखाते हैं:

कोटलिन

Java

जगह की जानकारी के डेटा के साथ काम करना

किसी Android डिवाइस के लिए उपलब्ध जगह की जानकारी के डेटा में डिवाइस की मौजूदा जगह की जानकारी शामिल होती है. जिसमें डिवाइस की जगह की जानकारी शामिल होती है. यह पता करने के लिए, अलग-अलग टेक्नोलॉजी के मिले-जुले रूप का इस्तेमाल किया जाता है. यह भी पता चलता है कि डिवाइस कहीं आने-जाने के लिए, पहले से तय किसी भौगोलिक सीमा या जियोफ़ेंस में मूव है या नहीं. आपके ऐप्लिकेशन की ज़रूरतों के हिसाब से, जगह की जानकारी के डेटा के साथ काम करने के कई तरीकों में से कोई एक चुना जा सकता है:

  • मेरी जगह लेयर, मैप पर डिवाइस की जगह को दिखाने का आसान तरीका उपलब्ध कराती है. यह डेटा नहीं देती है.
  • जगह की जानकारी के डेटा के लिए, प्रोग्राम के हिसाब से किए जाने वाले सभी अनुरोधों के लिए, Google Play services Location API का सुझाव दिया जाता है.
  • LocationSource इंटरफ़ेस की मदद से, अपनी पसंद के मुताबिक जगह की जानकारी उपलब्ध कराई जा सकती है.

जगह की जानकारी की अनुमतियाँ

अगर आपके ऐप्लिकेशन को उपयोगकर्ता की जगह की जानकारी ऐक्सेस करने की ज़रूरत है, तो आपको ऐप्लिकेशन में Android की जगह की जानकारी की अनुमतियां जोड़कर, इसकी अनुमति लेनी होगी.

Android, जगह की जानकारी की दो अनुमतियां देता है: ACCESS_COARSE_LOCATION और ACCESS_FINE_LOCATION. आपकी चुनी गई अनुमति से यह तय होता है कि एपीआई की मदद से, जगह की सटीक जानकारी दी गई या नहीं.

  • android.permission.ACCESS_COARSE_LOCATION – यह एपीआई को डिवाइस की जगह की अनुमानित जानकारी देने की अनुमति देता है. इस अनुमति से, जगह की जानकारी की मदद से डिवाइस की जगह की जानकारी का अनुमान लगाया जाता है. इसके बारे में, जगह की अनुमानित जानकारी वाले दस्तावेज़ में बताया गया है.
  • android.permission.ACCESS_FINE_LOCATION – यह एपीआई को, वाई-फ़ाई और मोबाइल सेल डेटा के साथ-साथ ग्लोबल पोज़िशनिंग सिस्टम (जीपीएस) समेत उपलब्ध लोकेशन प्रोवाइडर से जगह की सटीक जानकारी का पता लगाने की अनुमति देता है.

ऐप्लिकेशन मेनिफ़ेस्ट में अनुमतियां जोड़ें

अगर आपके ऐप्लिकेशन के काम करने के लिए सिर्फ़ जगह की अनुमानित जानकारी की ज़रूरत है, तो अपने ऐप्लिकेशन की मेनिफ़ेस्ट फ़ाइल में 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>

रनटाइम की अनुमतियों का अनुरोध करें

Android 6.0 (Marshmallow) में, अनुमतियों को मैनेज करने के लिए एक नया मॉडल लॉन्च किया गया है. इससे उपयोगकर्ताओं के लिए, ऐप्लिकेशन इंस्टॉल और अपग्रेड करते समय प्रोसेस आसान हो जाती है. अगर आपका ऐप्लिकेशन, एपीआई लेवल 23 या उसके बाद के वर्शन को टारगेट करता है, तो अनुमतियों के नए मॉडल का इस्तेमाल किया जा सकता है.

अगर आपका ऐप्लिकेशन, अनुमतियों के नए मॉडल के साथ काम करता है और डिवाइस पर Android 6.0 (Marshmallow) या उसके बाद का वर्शन चल रहा है, तो ऐप्लिकेशन को इंस्टॉल या अपग्रेड करते समय, उपयोगकर्ता को कोई अनुमति देने की ज़रूरत नहीं है. रनटाइम के दौरान, ऐप्लिकेशन को यह देखना होगा कि उसके पास ज़रूरी अनुमति है या नहीं. अगर उसके पास अनुमति नहीं है, तो उसे अनुमति का अनुरोध करना होगा. सिस्टम, उपयोगकर्ता को एक डायलॉग दिखाता है. इस डायलॉग बॉक्स में, अनुमति मांगने की सुविधा होती है.

बेहतरीन उपयोगकर्ता अनुभव के लिए, ज़रूरत के हिसाब से अनुमति का अनुरोध करना ज़रूरी है. अगर आपके ऐप्लिकेशन के काम करने के लिए जगह की जानकारी ज़रूरी है, तो आपको ऐप्लिकेशन शुरू होने पर जगह की जानकारी की अनुमति का अनुरोध करना चाहिए. ऐसा करने का एक अच्छा तरीका यह है कि आप एक गर्मजोशी से स्वागत स्क्रीन या विज़ार्ड का इस्तेमाल करें, जो उपयोगकर्ताओं को इस बारे में शिक्षित करता है कि अनुमति क्यों ज़रूरी है.

अगर ऐप्लिकेशन को उसके कुछ ही फ़ंक्शन के लिए अनुमति की ज़रूरत है, तो आपको जगह की जानकारी का अनुरोध सिर्फ़ तब करना चाहिए, जब ऐप्लिकेशन ऐसी कार्रवाई करता है जिसके लिए अनुमति की ज़रूरत हो.

ऐप्लिकेशन को उन मामलों को सही तरीके से मैनेज करना चाहिए जहां उपयोगकर्ता अनुमति नहीं देता है. उदाहरण के लिए, अगर किसी खास सुविधा के लिए अनुमति की ज़रूरत होती है, तो ऐप्लिकेशन उस सुविधा को बंद कर सकता है. अगर ऐप्लिकेशन के काम करने के लिए अनुमति ज़रूरी है, तो ऐप्लिकेशन उसकी सभी सुविधाओं को बंद कर सकता है. साथ ही, उपयोगकर्ता को यह बता सकता है कि उसे अनुमति देनी होगी.

नीचे दिया गया कोड सैंपल, 'मेरा स्थान' लेयर को चालू करने से पहले AndroidX लाइब्रेरी का इस्तेमाल करके, अनुमति की जांच करता है. इसके बाद, यह सहायता लाइब्रेरी से ActivityCompat.OnRequestPermissionsResultCallback को लागू करके, अनुमति के अनुरोध के नतीजे को हैंडल करता है:

Kotlin

// 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
    }
}

Java

// 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() को कॉल करें.

नीचे दिया गया नमूना, 'मेरी जगह' की लेयर के सामान्य इस्तेमाल को दिखाता है:

Kotlin



// 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
    }
}


      

Java


// 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 services Location API

अपने Android ऐप्लिकेशन में जगह की जानकारी जोड़ने के लिए, Google Play services Location API पसंदीदा तरीका है. इसके फ़ंक्शन से, ये काम किए जा सकते हैं:

  • डिवाइस की जगह की जानकारी हासिल करें.
  • जगह के बदलाव सुनें.
  • यदि डिवाइस चल रहा है, तो परिवहन का साधन ज्ञात करें.
  • पहले से तय भौगोलिक क्षेत्र बनाएं और उनकी निगरानी करें, जिन्हें जियोफ़ेंस कहा जाता है.

Location API की मदद से, बिजली की कम खपत करने वाले और जगह की जानकारी वाले ऐप्लिकेशन बनाना आसान हो जाता है. Android के लिए Maps SDK टूल की तरह, Location API को भी Google Play services SDK टूल के हिस्से के तौर पर उपलब्ध कराया जाता है. Location API के बारे में ज़्यादा जानकारी के लिए, कृपया Android ट्रेनिंग क्लास अपने ऐप्लिकेशन के लिए जगह की जानकारी को तैयार करना या Location API रेफ़रंस को देखें. कोड के उदाहरणों को Google Play services SDK टूल के हिस्से के तौर पर शामिल किया गया है.