【问题标题】:Google map for android my location custom button (error)适用于 android 的 Google 地图我的位置自定义按钮(错误)
【发布时间】:2016-12-15 02:13:01
【问题描述】:

我正在尝试移除我所在位置上的蓝点并显示自定义图像。 人们说它需要更改位置按钮。 我找到了这个答案。 Google map for android my location custom button 但这对我不起作用。在代码上,它看起来不错,没有红线。但是当我在手机上初始化并按下位置按钮时,它停止了。

有没有贴出完整代码的正文? 每个人都推荐这个答案,但我不确定哪个是错误的...... 我坚持这件事超过3天...... 请任何人帮助我..

Android 显示器错误

12-15 11:20:37.845 10853-10853/org.androidtown.realchangdeokgunge D/AndroidRuntime: Shutting down VM
12-15 11:20:37.855 10853-10853/org.androidtown.realchangdeokgunge W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x4166bd58)
12-15 11:20:37.855 10853-10853/org.androidtown.realchangdeokgunge E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                    Process: org.androidtown.realchangdeokgunge, PID: 10853
                                                                                    java.lang.NullPointerException
                                                                                        at org.androidtown.realchangdeokgunge.GPSActivity.getMyLocation(GPSActivity.java:118)
                                                                                        at org.androidtown.realchangdeokgunge.GPSActivity.access$000(GPSActivity.java:50)
                                                                                        at org.androidtown.realchangdeokgunge.GPSActivity$1.onClick(GPSActivity.java:135)
                                                                                        at android.view.View.performClick(View.java:4457)
                                                                                        at android.view.View$PerformClick.run(View.java:18501)
                                                                                        at android.os.Handler.handleCallback(Handler.java:733)
                                                                                        at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                                        at android.os.Looper.loop(Looper.java:136)
                                                                                        at android.app.ActivityThread.main(ActivityThread.java:5068)
                                                                                        at java.lang.reflect.Method.invokeNative(Native Method)
                                                                                        at java.lang.reflect.Method.invoke(Method.java:515)
                                                                                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
                                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:608)
                                                                                        at dalvik.system.NativeStart.main(Native Method)

代码错误

GPSActivity java:118
LatLng latLng = new LatLng(mLastLocation.getLatitude(), mLastLocation.getLongitude());

*我在上面链接的帖子中使用 mLastLocation 而不是“Double.parse....”。 我不知道为什么,但它显示红线错误。

GPSActivity java:50

public class GPSActivity extends FragmentActivity implements OnMapReadyCallback,
        GoogleApiClient.ConnectionCallbacks,
        GoogleApiClient.OnConnectionFailedListener,
        LocationListener,
        GoogleMap.OnInfoWindowClickListener{

GPSActivity java:135

getMyLocation();

【问题讨论】:

    标签: android google-maps button location


    【解决方案1】:

    mLastLocationnull。如果您从getLastLocation() 获取它,如果设备可能返回null 而不是返回有效位置。在尝试访问其成员之前,您需要检查它是否为 null --

    if(mLastLocation != null) {
        LatLng latLng = new LatLng(mLastLocation.getLatitude(), mLastLocation.getLongitude());
        // .... whatever else you need to do
    }
    

    【讨论】:

    • 感谢您的回答!帮了大忙!我需要了解如何在 mLastLocation 上输入数据......我正在尝试在 getMylocation 方法上“定位”。但是当我把它放在“位置”值上时,我还需要把它放在 setOnClickListener 的 onClick 方法中。问题是它不起作用。 onClick 方法“location”中的一个值出错了......我怎么能把一个值“location”......?
    猜你喜欢
    • 2014-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-15
    • 1970-01-01
    • 1970-01-01
    • 2015-03-28
    • 1970-01-01
    相关资源
    最近更新 更多