【问题标题】:Java Errors in Android AppAndroid 应用程序中的 Java 错误
【发布时间】:2013-03-18 07:22:10
【问题描述】:

我正在尝试在单击信息窗口时实现addProximityAlert

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);
        }
     }

});

这有“Java 错误”,我不确定如何修复它们。显然在public void addProximityAlert(double latitude, double longitude){ 行中,括号和逗号不是必需的,尽管它们是必需的。有人可以帮忙吗?

编辑:好的,所以我已经实现了下面的一些答案,但我仍然遇到问题。对于InfoWindowClickListener 类型,getBroadcast 方法未定义。有什么建议?

【问题讨论】:

  • 你在方法中定义了错误的方法

标签: java android marker proximity


【解决方案1】:

你有两个合并的方法声明:

public void onInfoWindowClick(Marker marker) {

public void addProximityAlert(double latitude, double longitude){

不确定您的意图是什么,但您需要在开始声明 addProximityAlert 之前关闭声明 onInfoWindowClick(Marker marker)

【讨论】:

  • 意图是在点击信息窗口时调用addProximityAlert方法。我还需要将解析后的经纬度变量传递给addProximityAlert方法
【解决方案2】:

试试这样:

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);
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多