Java源码示例:com.amap.api.maps2d.CameraUpdateFactory
示例1
private void cameraMove(LatLng latLng) {
userMoveCamera = false;
CameraUpdateFactory factory = new CameraUpdateFactory();
CameraUpdate cameraUpdate = factory.newLatLngZoom(latLng, (float) 15.5);
aMap.animateCamera(cameraUpdate, new AMap.CancelableCallback() {
@Override
public void onFinish() {
userMoveCamera = true;
}
@Override
public void onCancel() {
userMoveCamera = true;
}
});
}
示例2
private void addChooseMarker() {
//加入自定义标签
MarkerOptions centerMarkerOption = new MarkerOptions().position(myLocation).icon(successDescripter);
centerMarker = aMap.addMarker(centerMarkerOption);
centerMarker.setPositionByPixels(mapView.getWidth() / 2, mapView.getHeight() / 2);
handler.postDelayed(new Runnable() {
@Override
public void run() {
CameraUpdate update = CameraUpdateFactory.zoomTo(17f);
aMap.animateCamera(update, 1000, new AMap.CancelableCallback() {
@Override
public void onFinish() {
aMap.setOnCameraChangeListener(AMAPLocationActivity.this);
}
@Override
public void onCancel() {
}
});
}
}, 1000);
}
示例3
private void initAmap() {
if (aMap == null) {
aMap = mapView.getMap();
}
aMap.setLocationSource(this);// 设置定位监听
aMap.setMyLocationEnabled(true);
aMap.getUiSettings().setZoomControlsEnabled(false);
// aMap.setMyLocationType(AMap.LOCATION_TYPE_LOCATE);
CameraUpdate cameraUpdate = CameraUpdateFactory.zoomTo(15);
aMap.moveCamera(cameraUpdate);
movingDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.icon_loaction_choose_moving);
chooseDescripter = BitmapDescriptorFactory.fromResource(R.drawable.icon_loaction_choose);
successDescripter = BitmapDescriptorFactory.fromResource(R.drawable.icon_usecarnow_position_succeed);
geocodeSearch = new GeocodeSearch(this);
geocodeSearch.setOnGeocodeSearchListener(this);
}
示例4
private void addChooseMarker() {
MarkerOptions centerMarkerOption = new MarkerOptions().position(myLocation).icon(chooseDescripter);
centerMarker = aMap.addMarker(centerMarkerOption);
centerMarker.setPositionByPixels(mapView.getWidth() / 2, mapView.getHeight() / 2);
handler.postDelayed(new Runnable() {
@Override
public void run() {
CameraUpdate update = CameraUpdateFactory.zoomTo(17f);
aMap.animateCamera(update, 1000, new AMap.CancelableCallback() {
@Override
public void onFinish() {
aMap.setOnCameraChangeListener(AmapActivity.this);
}
@Override
public void onCancel() {
}
});
}
}, 1000);
}
示例5
@Override
public void onLocationChanged(AMapLocation aMapLocation) {
if (mOnLocationChangedListener == null || mAMapLocationClient == null
|| aMapLocation == null || aMapLocation.getErrorCode() != 0) {
// 定位失败了
deactivate();
ToastUtil.show("定位失败,请开启定位后再重新尝试!");
return;
}
// 当前位置
LatLng curLatLng = MapUtil.newLatLng(aMapLocation);
// 通知位置信息
mOnLocationChangedListener.onLocationChanged(aMapLocation);
if (mCurMarker == null) {
// 设置当前位置
mCurMarker = mAMap.addMarker(new MarkerOptions()
.anchor(0.5f,0.5f)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.location_marker)));
}
// 移动到指定位置
mCurMarker.setPosition(curLatLng);
// 移动到当前位置
mAMap.animateCamera(CameraUpdateFactory.newLatLngZoom(curLatLng, 16f));
}
示例6
@Override
public void onPoiSearched(PoiResult poiResult, int resultCode) {
if (resultCode != AMapException.CODE_AMAP_SUCCESS) {
Alog.e("搜索出错了");
return;
}
if (poiResult == null || poiResult.getQuery() == null) {
Alog.e("没有搜索到结果");
ToastUtil.show("没有搜索结果!");
return;
}
// 获取搜索的结果
List<PoiItem> poiItems = poiResult.getPois();
ViewUtil.setVisibility(mTvPrompt,
CollectionUtil.isEmpty(poiItems) ? View.VISIBLE : View.GONE);
mSearchResultAdapter.setSelectedPosition(0);
mSearchResultAdapter.setItems(poiItems);
mSearchResultAdapter.setBeginAddress(null);
mSearchResultAdapter.notifyDataSetChanged();
if (CollectionUtil.isNotEmpty(poiItems)) {
// 移动到第一个位置
PoiItem poiItem = mSearchResultAdapter.getItem(0);
LatLng latLng = MapUtil.newLatLng(poiItem.getLatLonPoint());
isItemClickAction = true;
mAMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 16f));
}
}
示例7
@Override
public void onMyLocationChange(Location location) {
LogUtil.e(TAG, "onMyLocationChange");
GeocodeSearch geocoderSearch = new GeocodeSearch(getContext());
geocoderSearch.setOnGeocodeSearchListener(this);
LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
aMap.moveCamera(CameraUpdateFactory.changeLatLng(latLng));
LatLonPoint latLonPoint = new LatLonPoint(location.getLatitude(), location.getLongitude());
RegeocodeQuery query = new RegeocodeQuery(latLonPoint, 10000, GeocodeSearch.AMAP);
geocoderSearch.getFromLocationAsyn(query);
}
示例8
@Override
public void onGeocodeSearched(GeocodeResult geocodeResult, int i) {
LogUtil.e(TAG, "onGeocodeSearched");
GeocodeAddress geocodeAddress = geocodeResult.getGeocodeAddressList().get(0);
LatLng latLng = new LatLng(geocodeAddress.getLatLonPoint().getLatitude(),
geocodeAddress.getLatLonPoint().getLongitude());
aMap.moveCamera(CameraUpdateFactory.changeLatLng(latLng));
}
示例9
/**
* 取得获得的坐标并移动地图到该坐标
* @param latLonPoint 获得的坐标
*/
@Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
public void onLatLngPointEvent(LatLonPoint latLonPoint) {
LogUtil.e(TAG, "moveToLatLngPoint()");
mLatLng = new LatLng(latLonPoint.getLatitude(), latLonPoint.getLongitude());
aMap.moveCamera(CameraUpdateFactory.changeLatLng(mLatLng));
}
示例10
/**
* 初始化坐标
*/
private void initLatLng() {
for (int i = 0; i < mLatLngList.size(); i++) {
Marker marker = mAMap.addMarker(new MarkerOptions());
marker.setPosition(mLatLngList.get(i));
marker.setTitle(String.valueOf(i + 1));
mAMap.moveCamera(CameraUpdateFactory.changeLatLng(mLatLngList.get(0)));
mAMap.moveCamera(CameraUpdateFactory.zoomTo(13));
}
}
示例11
/**
* 移动镜头到当前的视角。
*
* @since V2.1.0
*/
public void zoomToSpan() {
if (mPois != null && mPois.size() > 0) {
if (mamap == null)
return;
LatLngBounds bounds = getLatLngBounds();
mamap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 100));
}
}
示例12
@Override
public void onMapLoaded() {
// 设置所有maker显示在当前可视区域地图中
LatLngBounds bounds = new LatLngBounds.Builder().include(new LatLng(34.341568, 108.940174)).build();
aMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 10));
}
示例13
private void initAmap() {
if (aMap == null) {
aMap = mapView.getMap();
}
if (getIntent().hasExtra("location")) {
isPerview = true;
mMsg = getIntent().getParcelableExtra("location");
tvCurLocation.setVisibility(View.GONE);
returns.setVisibility(View.GONE);
if (model) {
CameraPosition location = new CameraPosition.Builder()
.target(new LatLng(mMsg.getLat(), mMsg.getLng())).zoom(18).bearing(0).tilt(30).build();
show(location);
} else {
aMap.addMarker(new MarkerOptions().anchor(0.5f, 0.5f)
.position(new LatLng(mMsg.getLat(), mMsg.getLng())).title(mMsg.getPoi())
.snippet(mMsg.getLat() + "," + mMsg.getLng()).draggable(false));
}
return;
}
aMap.setLocationSource(this);// 设置定位监听
aMap.setMyLocationEnabled(true);
aMap.getUiSettings().setZoomControlsEnabled(false);
aMap.getUiSettings().setMyLocationButtonEnabled(false);
CameraUpdate cameraUpdate = CameraUpdateFactory.zoomTo(15);//设置缩放监听
aMap.moveCamera(cameraUpdate);
successDescripter = BitmapDescriptorFactory.fromResource(R.drawable.icon_usecarnow_position_succeed);
geocodeSearch = new GeocodeSearch(this);
geocodeSearch.setOnGeocodeSearchListener(this);
}
示例14
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.myLocation:
CameraUpdate update = CameraUpdateFactory.changeLatLng(myLocation);
aMap.animateCamera(update);
break;
default:
break;
}
}
示例15
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.myLocation:
CameraUpdate update = CameraUpdateFactory.changeLatLng(myLocation);
aMap.animateCamera(update);
break;
default:
break;
}
}
示例16
@Override
public void onLocationChanged(AMapLocation aMapLocation) {
mProgressDialog.dismiss();
if (aMapLocation != null && aMapLocation.getErrorCode() == 0) {
mCorrectedLatLng = new LatLng(aMapLocation.getLatitude(), aMapLocation.getLongitude());
mRealLatLng = getRealLatLng(mCorrectedLatLng);
mAmap.animateCamera(CameraUpdateFactory.zoomTo(17));
mAmap.animateCamera(CameraUpdateFactory.changeLatLng(mCorrectedLatLng));
mLocationTextView.setText("lon: " + aMapLocation.getLongitude() + "° / lat: " + aMapLocation.getLatitude() + "°");
mAmap.clear();
mAmap.addMarker(new MarkerOptions().position(mCorrectedLatLng));
}
}
示例17
@Override
public void onMapClick(LatLng latLng) {
mCorrectedLatLng = latLng;
mRealLatLng = getRealLatLng(mCorrectedLatLng);
mLocationTextView.setText("lon: " + latLng.longitude + "° / lat: " + latLng.latitude + "°");
mAmap.clear();
mAmap.addMarker(new MarkerOptions().position(latLng));
mAmap.animateCamera(CameraUpdateFactory.changeLatLng(latLng));
}
示例18
private void initMapView() {
if (aMap == null) {
aMap = mapView.getMap();
aMap.setOnMapClickListener(this);// add the listener for click for amap object
}
LatLng shenzhen = new LatLng(22.5362, 113.9454);
aMap.addMarker(new MarkerOptions().position(shenzhen).title("Marker in Shenzhen"));
aMap.moveCamera(CameraUpdateFactory.newLatLng(shenzhen));
}
示例19
private void cameraUpdate(){
LatLng pos = new LatLng(droneLocationLat, droneLocationLng);
float zoomlevel = (float) 18.0;
CameraUpdate cu = CameraUpdateFactory.newLatLngZoom(pos, zoomlevel);
aMap.moveCamera(cu);
}
示例20
private void cameraUpdate() {
LatLng pos = new LatLng(mAircraftLat, mAircraftLng);
float zoomlevel = (float) 18.0;
CameraUpdate cu = CameraUpdateFactory.newLatLngZoom(pos, zoomlevel);
aMap.moveCamera(cu);
}
示例21
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (position != mSearchResultAdapter.getSelectedPosition()) {
PoiItem poiItem = mSearchResultAdapter.getItem(position);
LatLng latLng = MapUtil.newLatLng(poiItem.getLatLonPoint());
isItemClickAction = true;
mAMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 16f));
mSearchResultAdapter.setSelectedPosition(position);
mSearchResultAdapter.notifyDataSetChanged();
}
}
示例22
private void cameraUpdate(LatLng latLng) {
CameraUpdate cameraSigma =
CameraUpdateFactory.newCameraPosition(
new CameraPosition(latLng, 18, 0, 0));
mAMap.moveCamera(cameraSigma);
}
示例23
@Override
public void onLocationChanged(AMapLocation amapLocation) {
if (amapLocation != null) {
if (amapLocation.getErrorCode() == 0) {
//定位成功回调信息,设置相关消息
amapLocation.getLocationType();//获取当前定位结果来源,如网络定位结果,详见官方定位类型表
mLatitude = amapLocation.getLatitude();//获取纬度
mLongitude = amapLocation.getLongitude();//获取经度
amapLocation.getAccuracy();//获取精度信息
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = new Date(amapLocation.getTime());
df.format(date);//定位时间
amapLocation.getAddress();//地址,如果option中设置isNeedAddress为false,则没有此结果,网络定位结果中会有地址信息,GPS定位不返回地址信息。
amapLocation.getCountry();//国家信息
amapLocation.getProvince();//省信息
mCity = amapLocation.getCity();//城市信息
amapLocation.getDistrict();//城区信息
amapLocation.getStreet();//街道信息
amapLocation.getStreetNum();//街道门牌号信息
amapLocation.getCityCode();//城市编码
amapLocation.getAdCode();//地区编码
titleCenterTv.setText(amapLocation.getCity());
lp = new LatLonPoint(mLongitude, mLatitude);
Log.i(LOG, ">>>>> " + mCity + ", " + mLongitude + ", " + mLatitude);
// 如果不设置标志位,此时再拖动地图时,它会不断将地图移动到当前的位置
if (isFirstLoc) {
//设置缩放级别
aMap.moveCamera(CameraUpdateFactory.zoomTo(17));
//将地图移动到定位点
aMap.moveCamera(CameraUpdateFactory.changeLatLng(new LatLng(amapLocation.getLatitude(), amapLocation.getLongitude())));
//点击定位按钮 能够将地图的中心移动到定位点
mListener.onLocationChanged(amapLocation);
//添加图钉
mMarker = aMap.addMarker(getMarkerOptions(amapLocation));
isFirstLoc = false;
}
} else {
//显示错误信息ErrCode是错误码,errInfo是错误信息,详见错误码表。
Log.e("AmapError", "location Error, ErrCode:"
+ amapLocation.getErrorCode() + ", errInfo:"
+ amapLocation.getErrorInfo());
Toast.makeText(FindMapAroundAty.this, "定位失败", Toast.LENGTH_LONG).show();
}
}
}
示例24
private void initMapView() {
if (aMap == null) {
aMap = mapView.getMap();
aMap.setOnMapClickListener(this);// add the listener for click for amap object
}
aMap.moveCamera(CameraUpdateFactory.zoomTo(18));
}