简体   繁体   English

要在Google Maps API v2 for Android中使用或不使用getMyLocation()?

[英]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. 我目前正在开发一个利用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. 事实是,似乎不赞成使用getMyLocation()(我当前正在使用),这是根据android的开发人员站点进行的。 However, Eclipse is not showing any kind of warning sign of deprecation for this method. 但是,Eclipse对此方法没有显示任何过时的警告信号。 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. 尝试改用LocationClient实现。

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

You can enable the "my location layer" available on maps V2. 您可以启用地图V2上可用的“我的位置图层”。

map.setMyLocationEnabled (true)

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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