Java Errors in Android App

*爱你&永不变心* 提交于 2019-12-14 03:36:28

问题


I'm trying to to implement a addProximityAlert when an info window is clicked

googleMap.setOnInfoWindowClickListener(
            new OnInfoWindowClickListener(){
                public void onInfoWindowClick(Marker marker) {

    public void addProximityAlert(double latitude, double longitude){


             LatLng clickedMarkerLatLng = marker.getPosition();
                    double lat =  clickedMarkerLatLng.latitude;
                    double long1 =  clickedMarkerLatLng.longitude;

                Log.e("hello", "Output=" + lat + long1);

                   LocationManager lm;
             //   double lat=123,long1=34;    //Defining Latitude & Longitude
                  float radius=30;                         //Defining Radius
            Intent intent = new Intent(PROX_ALERT_INTENT);
            PendingIntent proximityIntent = PendingIntent.getBroadcast(this, 0, intent, 0);
            locationManager.addProximityAlert(
                lat, // the latitude of the central point of the alert region
                long1, // the longitude of the central point of the alert region
                POINT_RADIUS, // the radius of the central point of the alert region, in meters
                PROX_ALERT_EXPIRATION, // time for this proximity alert, in milliseconds, or -1 to indicate no expiration
                proximityIntent // will be used to generate an Intent to fire when entry to or exit from the alert region is detected
           );
           IntentFilter filter = new IntentFilter(PROX_ALERT_INTENT); 
           registerReceiver(new ProximityIntentReceiver(), filter);
        }
     }

});

This has "Java errors" and I'm unsure as to how to fix them. Apparently in line public void addProximityAlert(double latitude, double longitude){ the brackets and comma aren't necessary, despite them being needed. Can somebody help?

EDIT: OK, so I've implemented some of the answers below, but I'm still having problems. The getBroadcast method is undefined for the type InfoWindowClickListener. Any suggestions?


回答1:


You have two merged method declarations:

public void onInfoWindowClick(Marker marker) {

public void addProximityAlert(double latitude, double longitude){

Not sure what your intent is, but you need to close off the declaration of onInfoWindowClick(Marker marker) before beginning the declaration of addProximityAlert




回答2:


Try it like this:

googleMap.setOnInfoWindowClickListener(
                new OnInfoWindowClickListener(){
                    public void onInfoWindowClick(Marker marker) {

                        addProximityAlert(latitude,longitude);
         }

    });

 public void addProximityAlert(double latitude, double longitude){


         LatLng clickedMarkerLatLng = marker.getPosition();
                double lat =  clickedMarkerLatLng.latitude;
                double long1 =  clickedMarkerLatLng.longitude;

            Log.e("hello", "Output=" + lat + long1);

               LocationManager lm;
         //   double lat=123,long1=34;    //Defining Latitude & Longitude
              float radius=30;                         //Defining Radius
        Intent intent = new Intent(PROX_ALERT_INTENT);
        PendingIntent proximityIntent = PendingIntent.getBroadcast(this, 0, intent, 0);
        locationManager.addProximityAlert(
            lat, // the latitude of the central point of the alert region
            long1, // the longitude of the central point of the alert region
            POINT_RADIUS, // the radius of the central point of the alert region, in meters
            PROX_ALERT_EXPIRATION, // time for this proximity alert, in milliseconds, or -1 to indicate no expiration
            proximityIntent // will be used to generate an Intent to fire when entry to or exit from the alert region is detected
       );
       IntentFilter filter = new IntentFilter(PROX_ALERT_INTENT); 
       registerReceiver(new ProximityIntentReceiver(), filter);
    }


来源:https://stackoverflow.com/questions/15471594/java-errors-in-android-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!