本文整理汇总了Java中com.google.android.gms.maps.GoogleMap类的典型用法代码示例。如果您正苦于以下问题:Java GoogleMap类的具体用法?Java GoogleMap怎么用?Java GoogleMap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GoogleMap类属于com.google.android.gms.maps包,在下文中一共展示了GoogleMap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setMarkers
import com.google.android.gms.maps.GoogleMap; //导入依赖的package包/类
private void setMarkers(GoogleMap map, List<Restaurant> restaurants) {
if (map == null) {
return;
}
map.clear();
MarkerOptions options = new MarkerOptions().position(
new LatLng(Prefs.LastLatitude.getDouble(), Prefs.LastLongitude.getDouble()))
.icon(BitmapDescriptorFactory.fromResource(R.drawable.current_location));
map.addMarker(options);
for (Restaurant restaurant : restaurants) {
MarkerOptions markerOptions = new MarkerOptions().position(
new LatLng(restaurant.mLatitude, restaurant.mLongitude))
.title(restaurant.mName)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.restaurant_pin));
Marker marker = map.addMarker(markerOptions);
marker.setTag(restaurant);
}
mMap.setOnInfoWindowClickListener(mInfoWindowClickListener);
}
示例2: onMapReady
import com.google.android.gms.maps.GoogleMap; //导入依赖的package包/类
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mMap.setIndoorEnabled(true);
mMap.setMyLocationEnabled(false);
mMap.setOnMarkerClickListener(this);
mMap.setOnIndoorStateChangeListener(this);
mMap.setOnMapClickListener(this);
UiSettings mapUiSettings = mMap.getUiSettings();
mapUiSettings.setZoomControlsEnabled(false);
mapUiSettings.setMapToolbarEnabled(false);
// load all markers
LoaderManager lm = getLoaderManager();
lm.initLoader(TOKEN_LOADER_MARKERS, null, mMarkerLoader).forceLoad();
// load the tile overlays
lm.initLoader(TOKEN_LOADER_TILES, null, mTileLoader).forceLoad();
setupMap(true);
}
示例3: onMapReady
import com.google.android.gms.maps.GoogleMap; //导入依赖的package包/类
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// mMap.setOnMapClickListener(this);
Bundle bundle = getIntent().getExtras();
double r_long=bundle.getDouble("lattitude");
double r_lat=bundle.getDouble("longitude");
// Add a marker in Sydney and move the camera
LatLng mark = new LatLng(r_lat, r_long);
CircleOptions circleoptions=new CircleOptions().strokeWidth(2).strokeColor(Color.BLUE).fillColor(Color.parseColor("#500084d3"));
mMap.addMarker(new MarkerOptions().position(mark).title(getAddress(mark)));
mMap.moveCamera(CameraUpdateFactory.newLatLng(mark));
Circle circle=mMap.addCircle(circleoptions.center(mark).radius(5000.0));
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(circleoptions.getCenter(),getZoomLevel(circle)));
}
示例4: onMapReady
import com.google.android.gms.maps.GoogleMap; //导入依赖的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;
Toast.makeText(getApplicationContext(), "MAP READY", Toast.LENGTH_SHORT).show();
Log.e("MAP", "Map Ready");
// Add a marker at Polytechnic
LatLng poly = new LatLng(45.504628, -73.614675);
mMap.addMarker(new MarkerOptions().position(poly).title("Marker at Polytechnique"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(poly));
mMap.moveCamera(CameraUpdateFactory.zoomTo(mMap.getMaxZoomLevel()));
//Enable Current Location Button
mMap.setOnMyLocationButtonClickListener(this);
enableMyLocation();
}
示例5: onMapReady
import com.google.android.gms.maps.GoogleMap; //导入依赖的package包/类
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
//Initialize Google Play Services
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION)
== PackageManager.PERMISSION_GRANTED) {
buildGoogleApiClient();
mMap.setMyLocationEnabled(true);
}
} else {
buildGoogleApiClient();
mMap.setMyLocationEnabled(true);
}
}
示例6: moveMapCamera
import com.google.android.gms.maps.GoogleMap; //导入依赖的package包/类
@Override
public void moveMapCamera(final LatLng latLng) {
if (latLng.latitude == 0 && latLng.longitude == 0)
return;
final CameraPosition cameraPosition = new CameraPosition.Builder()
.target(latLng)
.zoom(12f)
.build();
googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition),
new GoogleMap.CancelableCallback() {
@Override
public void onFinish() {
googleMap.clear();
latitude = latLng.latitude;
longitude = latLng.longitude;
googleMap.addMarker(new MarkerOptions().position(latLng));
}
@Override
public void onCancel() {
// ignored
}
});
}
示例7: initMap
import com.google.android.gms.maps.GoogleMap; //导入依赖的package包/类
protected void initMap(GoogleMap map) {
goToLocation = true;
firstLocationRefresh = true;
if (map != null) {
MapsInitializer.initialize(getActivity());
RAApplication.getInstance().getGpsDetector().setGpsMapListener(new GPSDetector.GpsMapListener() {
@Override
public void onGpsMapListener(final Location location) {
ActivityUtil.runOnMainThread(new Runnable() {
@Override
public void run() {
if (refreshMyLocation) {
setCurrentLocation(location);
}
}
});
}
});
clearMap();
LatLng loc = new LatLng(Constants.LATITUDE_BELARUS, Constants.LONGITUDE_BELARUS);
map.moveCamera(CameraUpdateFactory.newLatLngZoom(loc, Constants.DEFAULT_CAMERA_ZOOM));
refreshMyLocation(loc);
initMapData();
}
}
示例8: onMapReady
import com.google.android.gms.maps.GoogleMap; //导入依赖的package包/类
@Override
public void onMapReady(GoogleMap googleMap) {
this.googleMap = googleMap;
this.googleMap.setOnMapClickListener(this);
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, 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;
}
this.googleMap.setMyLocationEnabled(true);
this.googleMap.setOnMyLocationButtonClickListener(this);
}
示例9: addTag
import com.google.android.gms.maps.GoogleMap; //导入依赖的package包/类
private void addTag(Context context, GoogleMap map, TagModel item, boolean addCache) {
LatLng location = new LatLng(item.getLatitude(), item.getLongitude());
BitmapDescriptor tagIcon = getTagIcon(item.getRoadCondition());
Marker marker = map.addMarker(new MarkerOptions()
.position(location)
.icon(tagIcon)
.anchor(0.5f, 0.5f)
.title(item.getName())
.snippet(item.getDescription()));
if (addCache && markersCache != null) {
markersCache.put(marker, item);
}
}
示例10: onMapReady
import com.google.android.gms.maps.GoogleMap; //导入依赖的package包/类
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mUiSettings = mMap.getUiSettings();
mMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
@Override
public void onMapClick(LatLng latLng) {
select.setVisibility(View.VISIBLE);
Log.d("latLng", latLng.latitude+" "+latLng.longitude);
mMap.addMarker(new MarkerOptions()
.position(latLng));
}
});
LatLng sydney = new LatLng(36.338193, 127.393331);
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
== PackageManager.PERMISSION_GRANTED) {
mMap.setMyLocationEnabled(true);
} else {
// Show rationale and request permission.
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, MY_PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION);
Toast.makeText(getApplicationContext(), "위치정보제공동의가 필요합니다.", Toast.LENGTH_SHORT).show();
}
mUiSettings.setZoomControlsEnabled(true);
}
示例11: onLocationChanged
import com.google.android.gms.maps.GoogleMap; //导入依赖的package包/类
@Override
public void onLocationChanged(Location location) {
mLastLocation = location;
if (mCurrLocationMarker != null) {
mCurrLocationMarker.remove();
}
map = new HashMap<String, String>();
map.put("LocationID", "0");
map.put("Latitude", Double.toString(location.getLatitude()));
map.put("Longitude", Double.toString(location.getLongitude()));
map.put("LocationName", "Current Position");
locations.add(map);
Latitude = Double.parseDouble(locations.get(0).get("Latitude"));
Longitude = Double.parseDouble(locations.get(0).get("Longitude"));
LatLng coordinate = new LatLng(Latitude, Longitude);
mMap.setMapType(com.google.android.gms.maps.GoogleMap.MAP_TYPE_HYBRID);
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(coordinate, 12));
if (mGoogleApiClient != null) {
LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, this);
}
}
示例12: onMapReady
import com.google.android.gms.maps.GoogleMap; //导入依赖的package包/类
public void onMapReady(GoogleMap googleMap) {
if (m_gMap == null) {
m_gMap = googleMap;
GoogleMap map = getMap();
if (map == null) {
MFBUtil.Alert(this, getString(R.string.txtError), getString(R.string.errNoGoogleMaps));
finish();
return;
}
map.setMapType(GoogleMap.MAP_TYPE_HYBRID);
UiSettings settings = map.getUiSettings();
settings.setCompassEnabled(false);
settings.setRotateGesturesEnabled(false);
settings.setScrollGesturesEnabled(true);
settings.setZoomControlsEnabled(false);
settings.setZoomGesturesEnabled(true);
View mapView = getFragmentManager().findFragmentById(R.id.mfbMap).getView();
if (mapView != null && mapView.getViewTreeObserver() != null && mapView.getViewTreeObserver().isAlive()) {
mapView.getViewTreeObserver().addOnGlobalLayoutListener(this);
}
map.setOnMarkerClickListener(this);
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) {
map.setMyLocationEnabled(true);
}
map.setOnMapLongClickListener(this);
updateMapElements();
}
}
示例13: onMapReady
import com.google.android.gms.maps.GoogleMap; //导入依赖的package包/类
/**
* Manipulates the map once available.
* This callback is triggered when the map is ready to be used.
*/
@Override
public void onMapReady(GoogleMap map) {
mMap = map;
mMapsManager = new MapsManager(this, map);
mGpxManager = new GpxManager(this);
// Check whether this app could get location
if (checkLocationPermission())
map.setMyLocationEnabled(true);
else
askPermission();
// Set the boundaries of Taiwan
MapUtils.setTaiwanBoundaries(map);
// 設定相機位置
if (lastCameraPosition == null)
map.moveCamera(CameraUpdateFactory.newLatLngZoom(TAIWAN_CENTER, STARTING_ZOOM));
else
map.moveCamera(CameraUpdateFactory.newCameraPosition(lastCameraPosition));
mMapsManager.onCameraMove();
// 開啟上次的GPX檔案
if (!mGpxFileList.isEmpty()) {
for (String filePath : mGpxFileList) {
File file = new File(filePath);
mGpxManager.addGpxFile(file, mMapsManager);
}
mGpxManager.refreshDialog();
}
// TODO blue dot beam to indicate user direction
}
示例14: onMapReady
import com.google.android.gms.maps.GoogleMap; //导入依赖的package包/类
@Override
public void onMapReady(GoogleMap googleMap) {
map_available=true;
map=googleMap;
map.moveCamera(CameraUpdateFactory.newCameraPosition(hamirpur));
map.setMapType(GoogleMap.MAP_TYPE_HYBRID);
map.addMarker(audi);
map.addMarker(nescafe);
map.addMarker(park);
map.addMarker(juice);
map.addMarker(ground);
map.addMarker(oat);
map.addMarker(sbi);
map.addMarker(ekta);
map.addMarker(h4);
map.addMarker(pgh);
map.addMarker(kbh);
map.addMarker(g1);
}
示例15: addMultiPolylineToMapAsMarkers
import com.google.android.gms.maps.GoogleMap; //导入依赖的package包/类
/**
* Add a MultiPolylineOptions to the map as markers
*
* @param shapeMarkers
* @param map
* @param multiPolyline
* @param polylineMarkerOptions
* @param globalPolylineOptions
* @return
*/
public MultiPolylineMarkers addMultiPolylineToMapAsMarkers(
GoogleMapShapeMarkers shapeMarkers, GoogleMap map,
MultiPolylineOptions multiPolyline,
MarkerOptions polylineMarkerOptions,
PolylineOptions globalPolylineOptions) {
MultiPolylineMarkers polylines = new MultiPolylineMarkers();
for (PolylineOptions polylineOptions : multiPolyline
.getPolylineOptions()) {
PolylineMarkers polylineMarker = addPolylineToMapAsMarkers(map,
polylineOptions, polylineMarkerOptions,
globalPolylineOptions);
shapeMarkers.add(polylineMarker);
polylines.add(polylineMarker);
}
return polylines;
}