简体   繁体   中英

To use or not to use getMyLocation () in google maps API v2 for android?

I'm currently working on an application that takes advantage of some simple features of the google maps api v2. This application is supposed to find user's current location and then display some places of my choice which also should be near to the user.

I've already achieved to find and display user location. The thing is that it seems that getMyLocation() (which I'm currently using) is deprecated, acording to android's developer site. However, Eclipse is not showing any kind of warning sign of deprecation for this method. I didn't knew this at the time I started writing my code.

So my question is: should I be worried for this to be a problem in the future if I plan to publish my app?

Here's my code for moving into user location:

if (map.getMyLocation() != null) {

        Toast.makeText(this, "You are here", Toast.LENGTH_LONG).show();
        map.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(
                map.getMyLocation().getLatitude(), map.getMyLocation()
                        .getLongitude()), 15));
    }

Thank you very much in advance for your time and your answers.

As said in the documentation, it is deprecated.

Try to use a LocationClient implementation instead.

http://developer.android.com/reference/com/google/android/gms/location/LocationClient.html

You can enable the "my location layer" available on maps V2.

map.setMyLocationEnabled (true)

check: http://developer.android.com/reference/com/google/android/gms/maps/GoogleMap.html#setMyLocationEnabled%28boolean%29

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM