【问题标题】:Different click event actions for marker in google maps apigoogle maps api中标记的不同点击事件操作
【发布时间】:2017-12-13 12:28:09
【问题描述】:

我有一组带有标记点击方法的地图活动。标记是从数据库中添加的,单击时会打开一个新的Activity。我遇到的问题是将当前位置分开以具有不同的点击事件。

我尝试创建第二个标记 (marker2) 并使用它,但我认为我没有正确处理它。下面的代码是我尝试用Hashmap 解决它,但我似乎无法正确解决它。

//This is the onclick method- i tried using an if statment if the value is not there to call the second marker. 
     mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {

            @Override
            public boolean onMarkerClick(Marker marker) {

                String venueID = mMarkerMap.get(marker.getId());
                String venueName = marker.getTitle();
                Intent intent = new Intent(MapsActivity.this, viewbeverageActivity.class);
                intent.putExtra(VENUE_NAME, venueName);
                intent.putExtra(VENUE_ID, venueID);
                startActivity(intent);

                if(venueID == null)
                {
                    onMarkerClick2(marker2);
                }

                return false;
            }

            public boolean onMarkerClick2(Marker marker2) {

                mMap2.getClass();

                return false;
            }
        });


//This is the location listener for the current location
 public boolean onMarkerClick(Marker marker) {
        return false;
    }

    private class MyLocationListener implements LocationListener{

        public void onLocationChanged (Location loc){
            if (loc != null){
                Toast.makeText(getBaseContext(),
                       "Current Location : Lat: " + loc.getLatitude() +
                                " Lng: " + loc.getLongitude(), Toast.LENGTH_LONG);
                LatLng p = new LatLng(loc.getLatitude(), loc.getLongitude());
                Geocoder geoCoder = new Geocoder(getBaseContext(), Locale.getDefault());
                List<Address> addresses = null;

                String add = "";
                try {
                       //String placeName = "YOU ARE HERE";
                    addresses = geoCoder.getFromLocation(loc.getLatitude(), loc.getLongitude(),1);
                    Address address = addresses.get(0);

                    if (addresses.size() > 0) {
                        for (int i = 0; i <= address.getMaxAddressLineIndex(); i++)
                            add += address.getAddressLine(i) + "\n";
                       // mMap2.addMarker(new MarkerOptions().position(p).title("You Are Here"));
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }

                mMap2.addMarker(new MarkerOptions()
                        .position(p)
                        .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN))
                        .title("YOU ARE HERE  ")
                        .snippet(KEY + "Population: 4,137,400"));
               // mMap.addMarker(new MarkerOptions().position(p).title("YOU ARE HERE"));
                mMap2.moveCamera(CameraUpdateFactory.newLatLngZoom(p, 12.0f));
            }
        }

当我单击当前位置时,它试图从数据库中查找与其余位置相同的详细信息,但没有成功,并导致应用程序崩溃并说啤酒应用程序不断停止。 on click 部分到达 esle 语句,但我只需要知道如何摆脱该方法并继续第二次点击

【问题讨论】:

    标签: java android google-maps-api-3


    【解决方案1】:

    你可以这样设置标签:

    Marker marker = new Marker() ;
    marker.setTag(position);// you can give ArrayList position and then get in on marker click method.
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-06-04
      • 2015-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-24
      • 1970-01-01
      相关资源
      最近更新 更多