2016-06-07 72 views
2

我在地图上显示车辆时,当我点击车辆时显示信息窗口,但我需要双击车辆,然后它会进入新的页面。我不'知道该怎么办,请大家帮me.here是我的代码如何处理双击Android应用程序中的标记

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback,GoogleMap.OnMarkerClickListener { 

     GoogleMap mMap; 
     RequestQueue requestQueue; 
     ArrayList<LatLng> points = null; 
     PolylineOptions polylineOptions; 
     Geocoder geocoder; 
     LocationListener locationListener; 
     TextView tv,tv_one,tv_two; 
     String string; 
     @Override 
     protected void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.activity_maps); 
      SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() 
        .findFragmentById(R.id.map); 
      mapFragment.getMapAsync(this); 
      points = new ArrayList<LatLng>(); 
      polylineOptions = new PolylineOptions(); 
      String URL = "http://b2ss2c.com/gtsapi/index.php?cmd=VEHICLE_DETAILS&deviceID=salim_fiat&accountID=gts&fromDate=23-May-2016&toDate=24-May-2016"; 
      final JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(URL, new Response.Listener<org.json.JSONArray>() { 
       @Override 
       public void onResponse(org.json.JSONArray response) { 
        for (int i = 0; i < response.length(); i++) { 

         try { 
          JSONObject jsonObject1 = response.getJSONObject(i); 
          String speed=jsonObject1.getString("speed"); 
          String deviceID=jsonObject1.getString("deviceID"); 
          String altitude=jsonObject1.getString("altitude"); 
          String fuelLevel=jsonObject1.getString("fuelLevel"); 
          LatLng latLng = new LatLng(jsonObject1.getDouble("latitude"),jsonObject1.getDouble("longitude")); 
          BitmapDescriptor image = BitmapDescriptorFactory.fromResource(R.drawable.car); 
          mMap.setOnMarkerClickListener(MapsActivity.this); 
          Marker marker= mMap.addMarker(new MarkerOptions().position(latLng).icon(image)); 
          marker.setTitle("DeviceID:"+deviceID+"\n"+"Speed:"+speed+"\n"+"Altitude:"+altitude+"\n"+"FuelLevel:"+fuelLevel); 
          mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 16)); 
          points.add(latLng); 
         } catch (JSONException e) { 
          e.printStackTrace(); 
         } 
        } 
        polylineOptions.addAll(points); 
        polylineOptions.width(4); 
        polylineOptions.color(Color.BLUE); 
        mMap.addPolyline(polylineOptions); 
       } 
      }, new Response.ErrorListener() { 
       @Override 
       public void onErrorResponse(VolleyError error) { 

       } 
      }); 
      requestQueue = Volley.newRequestQueue(this); 
      requestQueue.add(jsonArrayRequest); 
     } 
     @Override 
     public boolean onMarkerClick(Marker marker) { 
      geocoder=new Geocoder(getApplicationContext(), Locale.getDefault()); 
      if (Geocoder.isPresent()){ 
       try{ 
        List<Address> addresses=geocoder.getFromLocation(marker.getPosition().latitude,marker.getPosition().longitude,1); 
        if (addresses!=null && addresses.size()>0) { 
         android.location.Address address = addresses.get(0); 
         string = String.format("%s %s %s", address.getAddressLine(0),address.getSubLocality(),address.getLocality(), 
           address.getAdminArea(),address.getCountryName()); 
         String title=marker.getTitle(); 
         marker.setSnippet(title+"\n"+"Address:"+string); 
         marker.showInfoWindow(); 
        }else { 
         Toast.makeText(getApplicationContext(),"Address not found",Toast.LENGTH_SHORT).show(); 
        } 
       }catch (IOException e){ 
        e.printStackTrace(); 
       } 

      } 
      return false; 
     } 

     @Override 
     public void onMapReady(GoogleMap googleMap) { 
      mMap = googleMap; 

      mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() { 
       @Override 
       public View getInfoWindow(Marker marker) { 
        return null; 
       } 

       @Override 
       public View getInfoContents(Marker marker) { 
        View view=getLayoutInflater().inflate(R.layout.info_window,null); 
        tv=(TextView)view.findViewById(R.id.tv_address); 
        tv_one=(TextView)view.findViewById(R.id.tv_one); 
        tv_two=(TextView)view.findViewById(R.id.tv_two); 
        String snippet= marker.getSnippet(); 
        tv_one.setText(snippet); 
        return view; 
       } 
      }); 

     } 


    } 

回答

0

您当前正在启动您在使用onMarkerClick API标志的单个点击活动。为什么不使用定时器机制,它会记录点击次数。您可以在以下步骤中执行此操作

  1. 点击记录时间&标记的ID。
  2. 每当你在标记上得到点击事件。检查ID是否与前一个相同,并且两个事件之间的时间都小于某个阈值。
  3. 如果是,请启动您的活动。
  4. 如果否,清除保存的ID到新的ID并记录时间。
+0

谢谢你的重播,我会检查它并让你知道@Neji –

+0

是否奏效? – Neji

+0

仍然我正在努力 –

相关问题