當前位置: 首頁>>代碼示例>>Java>>正文


Java OnMapClickListener類代碼示例

本文整理匯總了Java中com.google.android.gms.maps.GoogleMap.OnMapClickListener的典型用法代碼示例。如果您正苦於以下問題:Java OnMapClickListener類的具體用法?Java OnMapClickListener怎麽用?Java OnMapClickListener使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


OnMapClickListener類屬於com.google.android.gms.maps.GoogleMap包,在下文中一共展示了OnMapClickListener類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onCreate

import com.google.android.gms.maps.GoogleMap.OnMapClickListener; //導入依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	if (!isNetworkAvailable(this)) {
		startNetworkUnavailableDialog();
	}
	
	setContentView(R.layout.activity_geolocation);
	map = ((MapFragment)getFragmentManager().findFragmentById(R.id.map)).getMap();
	
	Intent intent = getIntent();
	Geolocation location = (Geolocation) intent.getSerializableExtra(EXTRA_LOCATION);
	LatLng mapPosition = new LatLng(location.getLatitude(), location.getLongitude());
	marker = map.addMarker(new MarkerOptions().position(mapPosition));
	map.animateCamera(CameraUpdateFactory.newLatLng(mapPosition));
	
	map.setOnMapClickListener(new OnMapClickListener() {
		@Override
		public void onMapClick(LatLng point) {
			marker.setPosition(point);
			map.animateCamera(CameraUpdateFactory.newLatLng(point));
		}
	});
}
 
開發者ID:CMPUT301W15T09,項目名稱:Team9Project,代碼行數:25,代碼來源:GeolocationActivity.java

示例2: onMapReady

import com.google.android.gms.maps.GoogleMap.OnMapClickListener; //導入依賴的package包/類
@Override
public void onMapReady(GoogleMap map) {
    mLocationClient = getLocationClient();
    mLocationClient.addListener(this);

    updateMapPosition();

    if (mNew) {
        mMapView.setShowInfoWindow(true);
        mMapView.setShowAccuracy(true);
    }

    map.setOnMapClickListener(new OnMapClickListener() {
        @Override
        public void onMapClick(LatLng loaction) {
            viewMap();
        }
    });

    map.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
        @Override
        public boolean onMarkerClick(Marker marker) {
            viewMap();
            return true;
        }
    });
}
 
開發者ID:suomenriistakeskus,項目名稱:oma-riista-android,代碼行數:28,代碼來源:EditActivity.java

示例3: onResume

import com.google.android.gms.maps.GoogleMap.OnMapClickListener; //導入依賴的package包/類
@Override
public void onResume() {
    super.onResume();
    
    // Set up map if we haven't done so yet
    if (map == null) {
        // Remove the toolbar
        map = mapFragment.getMap();
        UiSettings settings = map.getUiSettings();
        settings.setMapToolbarEnabled(false);
        
        if (editable) {
            map.setOnMapClickListener(new OnMapClickListener() {
                @Override
                public void onMapClick(LatLng arg0) {
                    launchSelectLocationActivity();
                }
            });
        }
    }
    
    updateMap();
}
 
開發者ID:TravelTracker,項目名稱:TravelTracker,代碼行數:24,代碼來源:SelectLocationFragment.java

示例4: getViews

import com.google.android.gms.maps.GoogleMap.OnMapClickListener; //導入依賴的package包/類
private void getViews(View v) {
  // (MapFragment) getChildFragmentManager().findFragmentById(R.id.map);
  mMap = ((SupportMapFragment) getActivity().getSupportFragmentManager()
      .findFragmentById(R.id.map)).getMap();
  mMap.getUiSettings().setMyLocationButtonEnabled(true);
  mMap.setOnMapClickListener(new OnMapClickListener() {

    @Override
    public void onMapClick(LatLng point) {
      // TODO Auto-generated method stub
      mMap.addMarker(new MarkerOptions().position(point).title("Point")
          .snippet("Population: 4,137,400")
          .icon(BitmapDescriptorFactory.fromResource(R.drawable.marker))
          .draggable(true));
      rectOptions.add(point);
      if (polyline != null) {
        polyline.remove();
      }
      polyline = mMap.addPolyline(rectOptions);
    }
  });
}
 
開發者ID:liyaguang,項目名稱:PalHunterClient,代碼行數:23,代碼來源:GoogleMapFragment.java

示例5: _initilizeMap

import com.google.android.gms.maps.GoogleMap.OnMapClickListener; //導入依賴的package包/類
/**
 * Initialize the map view and set map click listener to map view. Tapping on any location will
 * show the marker on the location.
 */
private void _initilizeMap() {
    googleMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
            .getMap();

    if (googleMap == null) {
        _showMsg("Sorry! unable to create maps");
        return;
    }

    if (GeoLocation.getGpsStatus()) {
        if (defaultLat != 0 && defaultLng != 0) {
            _setLocation(defaultLat, defaultLng, false);
        } else {
            _setLocation(GeoLocation.getLatitude(), GeoLocation.getLongitude(), false);
        }
    } else {
        _showSettingsAlert();
    }

    googleMap.setOnMapClickListener(new OnMapClickListener() {

        @Override
        public void onMapClick(LatLng latLng) {
            latitude = latLng.latitude;
            longitude = latLng.longitude;
            MarkerOptions markerOptions = new MarkerOptions();
            markerOptions.title("latitude" + latLng.latitude + ":" + latLng.longitude);
            markerOptions.position(latLng);
            googleMap.clear();
            googleMap.addMarker(markerOptions);
            googleMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
        }
    });
}
 
開發者ID:egovernments,項目名稱:egov-mobile,代碼行數:39,代碼來源:MapActivity.java

示例6: initializeTracker

import com.google.android.gms.maps.GoogleMap.OnMapClickListener; //導入依賴的package包/類
@TargetApi(Build.VERSION_CODES.M)
private void initializeTracker() {
    app.textViewMessage1.setText(getString(R.string.tracker));
    app.layoutTopMessages.setBackgroundColor(getColor(R.color.teal600));
    googleMap.setOnMapClickListener(
            new OnMapClickListener() {
                @Override
                public void onMapClick(LatLng point) {
                    return; // do noth!
                }
            });
}
 
開發者ID:dmsl,項目名稱:tvm,代碼行數:13,代碼來源:MainActivity.java

示例7: initializeLogger

import com.google.android.gms.maps.GoogleMap.OnMapClickListener; //導入依賴的package包/類
@TargetApi(Build.VERSION_CODES.M)
private void initializeLogger() {
    app.textViewMessage1.setText(getString(R.string.logger));
    app.layoutTopMessages.setBackgroundColor(getColor(R.color.teal600));
    loggerSavedSpots = new ArrayList<Marker>();
    app.currentCoordinates = new LatLng(0, 0);
    googleMap.setOnMapClickListener(
            new OnMapClickListener() {

                @Override
                public void onMapClick(LatLng point) {

                    // Update coordinates
                    app.currentCoordinates = point;
                    updateDeveloperInfoLabels();

                    // Draw marker on this point

                    // If previous point exists, remove it
                    if (loggerTempMarker != null) {
                        loggerTempMarker.setPosition(point);
                        return;
                    }

                    // Add marker
                    loggerTempMarker =
                            googleMap.addMarker(
                                    new MarkerOptions()
                                            .position(point)
                                            .anchor(0.5f, 0.5f)
                                            .icon(
                                                    BitmapDescriptorFactory.fromResource(
                                                            R.drawable
                                                                    .vm_blue_dot_obscured_on)));
                }
            });
}
 
開發者ID:dmsl,項目名稱:tvm,代碼行數:38,代碼來源:MainActivity.java

示例8: onCreate

import com.google.android.gms.maps.GoogleMap.OnMapClickListener; //導入依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_main);

	// setting location manager to perform location related operations
	LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

	// Requesting location manager for location updates
	locationManager.requestLocationUpdates(
			LocationManager.NETWORK_PROVIDER, 1, 1, this);

	// To get map from MapFragment from layout
	googleMap = ((MapFragment) getFragmentManager().findFragmentById(
			R.id.map)).getMap();

	// To change the map type to Satellite
	 //googleMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);

	// To show our current location in the map with dot
	 googleMap.setMyLocationEnabled(true);

	// To listen action whenever we click on the map
	googleMap.setOnMapClickListener(new OnMapClickListener() {

		@Override
		public void onMapClick(LatLng latLng) {
			/*
			 * LatLng:Class will give us selected position latigude and
			 * longitude values
			 */
			Toast.makeText(getApplicationContext(), latLng.toString(),
					Toast.LENGTH_LONG).show();
		}
	});

}
 
開發者ID:Jason-F,項目名稱:University-GoDev,代碼行數:38,代碼來源:MainActivity.java

示例9: initMap

import com.google.android.gms.maps.GoogleMap.OnMapClickListener; //導入依賴的package包/類
private void initMap() {
  mMap = mMapView.getMap();
  mMap.getUiSettings().setMyLocationButtonEnabled(true);
  mMap.setMyLocationEnabled(true);
  mMap.setOnMapClickListener(new OnMapClickListener() {
    @Override
    public void onMapClick(LatLng point) {
      // TODO Auto-generated method stub
      mMap.addMarker(new MarkerOptions().position(point).title("Point")
          .snippet(point.toString())
          .icon(BitmapDescriptorFactory.fromResource(R.drawable.marker))
          .draggable(true));
      rectOptions.add(point);
      if (polyline != null) {
        polyline.remove();
      }
      polyline = mMap.addPolyline(rectOptions);
    }
  });
  if (cameraPosition == null) {
    mMap.setOnMyLocationChangeListener(new GoogleMap.OnMyLocationChangeListener() {
      @Override
      public void onMyLocationChange(Location location) {

        CameraUpdate center = CameraUpdateFactory.newLatLng(new LatLng(
            location.getLatitude(), location.getLongitude()));
        CameraUpdate zoom = CameraUpdateFactory.zoomTo(18);
        mMap.moveCamera(center);
        mMap.animateCamera(zoom);
        mMap.setOnMyLocationChangeListener(null);
      }
    });
  }
}
 
開發者ID:liyaguang,項目名稱:PalHunterClient,代碼行數:35,代碼來源:HomeFragment.java

示例10: whenMapClick

import com.google.android.gms.maps.GoogleMap.OnMapClickListener; //導入依賴的package包/類
/**
 * when map is clicked
 *
 * @param callback
 */
public void whenMapClick(final ClickCallback callback) {
    map.setOnMapClickListener(new OnMapClickListener() {
        @Override
        public void onMapClick(LatLng latLng) {
            callback.clicked(map, latLng);
        }
    });
}
 
開發者ID:kewang,項目名稱:map-controller,代碼行數:14,代碼來源:MapController.java

示例11: setOnMapClickListener

import com.google.android.gms.maps.GoogleMap.OnMapClickListener; //導入依賴的package包/類
@Override
public final void setOnMapClickListener(OnMapClickListener listener) {
    map.setOnMapClickListener(listener);
}
 
開發者ID:mosquitolabs,項目名稱:referendum_1o_android,代碼行數:5,代碼來源:GoogleMapWrapper.java

示例12: onMapReady

import com.google.android.gms.maps.GoogleMap.OnMapClickListener; //導入依賴的package包/類
/**
 * Manipulates the map once available.
 * This callback is triggered when the map is ready to be used.
 * This is where we can add markers or lines, add listeners or move the camera. In this case,
 * we just add a marker near Sydney, Australia.
 * If Google Play services is not installed on the device, the user will be prompted to install
 * it inside the SupportMapFragment. This method will only be triggered once the user has
 * installed Google Play services and returned to the app.
 */
@Override
public void onMapReady(GoogleMap googleMap) {
	mMap = googleMap;
	mMap.setMyLocationEnabled(true);
	mMap.setOnMapClickListener(new OnMapClickListener() {

		@Override
		public void onMapClick(LatLng latlng) {
			Intent intent = new Intent(MapActivity.this,
					ForecastActivity.class);
			Bundle extras = new Bundle();
			extras.putParcelable(Constants.PARAM_LATLNG, latlng);
			intent.putExtras(extras);
			intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
					| Intent.FLAG_ACTIVITY_NEW_TASK);
			startActivity(intent);
		}
	});
	if (getIntent().getBooleanExtra(Constants.PARAM_NO_LOCATION, false)) {
		Toast.makeText(this, R.string.no_location, Toast.LENGTH_SHORT)
				.show();
	}


	LatLng myPosition;


	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;
	}
	googleMap.setMyLocationEnabled(true);
	LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
	Criteria criteria = new Criteria();
	String provider = locationManager.getBestProvider(criteria, true);
	Location location = locationManager.getLastKnownLocation(provider);


	if (location != null) {
		double latitude = location.getLatitude();
		double longitude = location.getLongitude();
		LatLng latLng = new LatLng(latitude, longitude);
		myPosition = new LatLng(latitude, longitude);


		LatLng coordinate = new LatLng(latitude, longitude);
		CameraUpdate yourLocation = CameraUpdateFactory.newLatLngZoom(coordinate, 19);
		mMap.animateCamera(yourLocation);
	}
}
 
開發者ID:deanpanayotov,項目名稱:simple_weather,代碼行數:66,代碼來源:MapActivity.java

示例13: onCreate

import com.google.android.gms.maps.GoogleMap.OnMapClickListener; //導入依賴的package包/類
/**
 * Perform initialization of all fragments and loaders.
 *
 * @param savedInstanceState Bundle from Google SDK
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);
    setUpMapIfNeeded();

    // Getting Google Play availability status
    int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext());

    if (status != ConnectionResult.SUCCESS) { // Google Play Services are not available

        int requestCode = 10;
        Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this, requestCode);
        dialog.show();

    } else { // Google Play Services are available
        // Getting reference to SupportMapFragment of the activity_maps
        SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);

        // Getting Map for the SupportMapFragment
        mMap = fm.getMap();

        if(savedInstanceState != null){
            getItemsFromSaveBundle(savedInstanceState);

            // Redraw the map
            for (HashMap.Entry<Integer, List<Station>> entry : listOfStationsBaseOnHighwayid.entrySet()) {
                int highwayid = (int)entry.getKey();
                List<Station> tStationList = entry.getValue();
                int colorHighlightTheFreeWay = generatePairhighWayColor(highwayid);
                drawHighway(tStationList, colorHighlightTheFreeWay);
            }
        }
        else {
            activeAsyncs = 0;    // Make sure that we don't get stuck somehow
            initLoadingDialog();
            fetchHighwayData();
        }
    }


    // overwrite onMapClickListener to let users drag markerOptions in the map
    mMap.setOnMapClickListener(new OnMapClickListener() {
        @Override
        public void onMapClick(LatLng point) {
            drawMarker(point);
        }
    });

    goToDatePickUp();
}
 
開發者ID:Routelandia,項目名稱:routelandia-android,代碼行數:57,代碼來源:MapsActivity.java

示例14: setOnMapClickListener

import com.google.android.gms.maps.GoogleMap.OnMapClickListener; //導入依賴的package包/類
@Override
public final void setOnMapClickListener(OnMapClickListener listener) {
	map.setOnMapClickListener(listener);
}
 
開發者ID:mtransitapps,項目名稱:mtransit-for-android,代碼行數:5,代碼來源:GoogleMapWrapper.java

示例15: onCreate

import com.google.android.gms.maps.GoogleMap.OnMapClickListener; //導入依賴的package包/類
@Override
  protected void onCreate(Bundle savedInstanceState) 
  {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_google_map);
      
      // initialize icon drawables
      locIcon = R.drawable.bluedot;
      schoolIcon = R.drawable.university;
      workIcon = R.drawable.workoffice;
      beerIcon = R.drawable.beergarden;
      
      // initialize the map
      if(googleMap == null)
      {	
      	// get the map fragment and the map object
      	mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.map);
      	googleMap = mapFragment.getMap();
      	
      	// make sure the map exists before using
      	if(googleMap != null)
	{
      		// setup the map objects
              setupObjects();
              		
              // set the location
      		googleMap.moveCamera(CameraUpdateFactory.newCameraPosition(camOriginal));
              
              // click listener
              googleMap.setOnMapClickListener(new OnMapClickListener()
              {
			@Override
			public void onMapClick(LatLng loc) 
			{
				updateMapFromClick(loc);
			}
              });
              
	}
}
  }
 
開發者ID:SDSMT-CSC,項目名稱:CS492-FA13,代碼行數:42,代碼來源:MyGoogleMap.java


注:本文中的com.google.android.gms.maps.GoogleMap.OnMapClickListener類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。