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

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

कोड सैंपल

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).

आपका ऐप्लिकेशन इन इवेंट का जवाब दे सकता है:

  • अगर उपयोगकर्ता मेरा स्थान बटन पर क्लिक करता है, तो आपके ऐप्लिकेशन को onMyLocationButtonClick() कॉलबैक GoogleMap.OnMyLocationButtonClickListener.
  • अगर उपयोगकर्ता, मेरा स्थान वाले नीले बिंदु पर क्लिक करता है, तो आपके ऐप्लिकेशन को onMyLocationClick() कॉलबैक GoogleMap.OnMyLocationClickListener.

Google Play services Location API

पसंदीदा तरीका, Google Play services में Location API है का इस्तेमाल करें. इसमें ये शामिल हैं जिसमें आपको ये काम करने की सुविधा मिलती है:

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

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