마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

구글맵 연동하기 문제가 있습니다. ㅠㅠㅠ

0 추천
현재 인텐트에서 지도 버튼을 누르면

현재 인텐트에 받아놓은 버스정류장의 위도, 경도 좌표를 지도 인텐트로 넘겨 구글맵을 연동시키고 그 위치에

마커를 찍고자 합니다. 자꾸 앱을 키면 실행이 되다 중간에 중단이 되는데 도저히 제가 뭘 잘못했는지 모르겠어서 질문 올립니다.....

----구글맵 연동할 클래스 입니다-----

import android.*;

public class MapLocation extends FragmentActivity implements OnMapReadyCallback {

    private GoogleMap gMap;
    Intent intent = this.getIntent();
    double currLatitude=intent.getDoubleExtra("lat",-1);
    double currLongitude=intent.getDoubleExtra("lon",-1);
    String string="";
    LatLng place;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        place = new LatLng(currLatitude, currLongitude);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_map);
        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);
    }
     @Override
    public void onMapReady(GoogleMap googleMap) {
        gMap = googleMap;
         gMap.getUiSettings().setZoomControlsEnabled(true);
         gMap.getUiSettings().setCompassEnabled(true);
         gMap.getUiSettings().setMapToolbarEnabled(true);

//         // LatLng : 위도 경도 잡아주는 객체
//      //   LatLng place = new LatLng(currLatitude, currLongitude);
//
//         // 쥐잉~ 하면서 카메라 줌
//         // 20 : 확대하는 정도
         CameraPosition cameraPosition = new CameraPosition.Builder().target(place).zoom(15).build();
//
         gMap.animateCamera(CameraUpdateFactory.newCameraPosition((cameraPosition)));
//
//         // 좌표에 Marker가 꽂히게
        gMap.addMarker(new MarkerOptions().position(place).title("검색한 정류소"));
         gMap.addMarker(new MarkerOptions().position(place).snippet(string));

         Toast.makeText(this, "lat: " + currLatitude + ", lon: " + currLongitude, Toast.LENGTH_SHORT).show();
         if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
             // TODO: Consider calling
             //    ActivityCompat#requestPermissions
             // here to request the missing permissions, and then overriding
             //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
             //                                          int[] grantResults)
             // to handle the case where the user grants the permission. See the documentation
           // for ActivityCompat#requestPermissions for more details.
             return;
         }
         gMap.setMyLocationEnabled(true);
    }
}

------현재 인텐트의 클래스입니다------

 

//버스 위치 지도버튼 눌렀을때
        busBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                // do something when the button is clicked
                double d1=Double.valueOf(currentStation.getGpsX()).doubleValue();
                double d2=Double.valueOf(currentStation.getGpsY()).doubleValue();

                //  Toast.makeText(getApplicationContext(), "d1="+ map.currLatitude, Toast.LENGTH_SHORT).show();
               //map=new MapLocation(d1,d2,currentStation.getStNm());

                //map.MoveMapLocation(d1,d2);
                Intent intent1 = new Intent(StationActivity.this, MapLocation.class);
                intent1.putExtra("lat", d1);
               intent1.putExtra("lon", d2);
              // intent1.putExtra("title", currentStation.getStNm());
                 startActivity(intent1);
                // Intent intent1 = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:"+d1+","+d2));
               // intent1.setPackage("com.google.android.apps.maps");
               // startActivity(intent1);
            }
        });

 

 

 

정류장의 좌표를 받아오는것은 문제가 전혀없습니다

문제는 인텐트로 넘겨줄때 발생하는 것입니다....

 

그치만 그 원인을 아무리 봐도 모르겠습니다 ㅜㅜㅜ 제발 알려주실수있을까요

----------------오류 로그입니다--------------

09-04 10:39:33.087 5206-5206/com.example.sy.bus_alime E/AndroidRuntime: FATAL EXCEPTION: main
                                                                        Process: com.example.sy.bus_alime, PID: 5206
                                                                        java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.sy.bus_alime/com.example.sy.bus_alime.MapLocation}: java.lang.NullPointerException: Attempt to invoke virtual method 'double android.content.Intent.getDoubleExtra(java.lang.String, double)' on a null object reference
                                                                            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2236)
                                                                            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
                                                                            at android.app.ActivityThread.access$800(ActivityThread.java:151)
                                                                            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
                                                                            at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                            at android.os.Looper.loop(Looper.java:135)
                                                                            at android.app.ActivityThread.main(ActivityThread.java:5254)
                                                                            at java.lang.reflect.Method.invoke(Native Method)
                                                                            at java.lang.reflect.Method.invoke(Method.java:372)
                                                                            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
                                                                            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
                                                                         Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'double android.content.Intent.getDoubleExtra(java.lang.String, double)' on a null object reference
고이소 (160 포인트) 님이 2017년 9월 4일 질문
고이소님이 2017년 9월 4일 수정

답변 달기

· 글에 소스 코드 보기 좋게 넣는 법
· 질문에 대해 추가적인 질문이나 의견이 있으면 답변이 아니라 댓글로 달아주시기 바랍니다.
표시할 이름 (옵션):
개인정보: 당신의 이메일은 이 알림을 보내는데만 사용됩니다.
스팸 차단 검사:
스팸 검사를 다시 받지 않으려면 로그인하거나 혹은 가입 하세요.
...