Java源码示例:com.amap.api.services.geocoder.GeocodeSearch

示例1
/**
 * 初始化AMap对象
 */
private void init() {
	if (aMap == null) {
		aMap = mapView.getMap();
		regeoMarker = aMap.addMarker(new MarkerOptions().anchor(0.5f, 0.5f)
				.icon(BitmapDescriptorFactory
						.defaultMarker(BitmapDescriptorFactory.HUE_RED)));
		aMap.setOnMarkerClickListener(this);
	}
	Button regeoButton = (Button) findViewById(R.id.geoButton);
	Button regeoButton_ = (Button)findViewById(R.id.regeoButton);
	regeoButton.setText("ResGeoCoding(39.90865,116.39751)");
	regeoButton.setOnClickListener(this);
	regeoButton_.setVisibility(View.VISIBLE);
	regeoButton_.setText("逆地理编码同步方法(线程池)");
	regeoButton_.setOnClickListener(this);
	geocoderSearch = new GeocodeSearch(this);
	geocoderSearch.setOnGeocodeSearchListener(this);
	progDialog = new ProgressDialog(this);
}
 
示例2
/**
 * 响应逆地理编码的批量请求
 */
private void getAddresses() {
	List<LatLonPoint> geopointlist = readLatLonPoints();
	for (final LatLonPoint point : geopointlist) {
		ThreadUtil.getInstance().execute(new Runnable() {
			@Override
			public void run() {
				try {
					RegeocodeQuery query = new RegeocodeQuery(point, 200,
							GeocodeSearch.AMAP);// 第一个参数表示一个Latlng,第二参数表示范围多少米,第三个参数表示是火系坐标系还是GPS原生坐标系
					RegeocodeAddress result = geocoderSearch.getFromLocation(query);// 设置同步逆地理编码请求

					if (result != null && result.getFormatAddress() != null) {
						aMap.addMarker(new MarkerOptions()
								.position(new LatLng(point.getLatitude(), point.getLongitude()))
								.title(result.getFormatAddress()));
					}
				} catch (AMapException e) {
					Message msg = msgHandler.obtainMessage();
					msg.arg1 = e.getErrorCode();
					msgHandler.sendMessage(msg);
				}
			}
		});
	}
}
 
示例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 initMap() {
    aMap = mMapView.getMap();
    mUiSettings = aMap.getUiSettings();
    mUiSettings.setZoomControlsEnabled(false);
    mUiSettings.setScaleControlsEnabled(true);
    mUiSettings.setMyLocationButtonEnabled(false);

    //焊死位置,未得许可不能更改
    if (canSelect||AccountModel.getInstance().checkIsSuper()){
        aMap.setOnMapClickListener(this);
    }
    aMap.setOnMarkerClickListener(this);
    mGeocoderSearch = new GeocodeSearch(this);
    mGeocoderSearch.setOnGeocodeSearchListener(this);
    initMyPoint();
}
 
示例5
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_map);

    ActionBar actionBar = getActionBar();
    if (actionBar != null) actionBar.setDisplayHomeAsUpEnabled(true);

    mMapView = findViewById(R.id.map_view);
    mMapView.onCreate(savedInstanceState);

    mListView = findViewById(R.id.list_view);
    mTvPrompt = findViewById(R.id.tv_prompt);
    mSearchResultAdapter = new SearchResultAdapter(this);
    mListView.setAdapter(mSearchResultAdapter);
    mListView.setOnItemClickListener(this);

    mAMap = mMapView.getMap();

    mAMap.getUiSettings().setZoomControlsEnabled(false);
    mAMap.setLocationSource(this);
    mAMap.getUiSettings().setMyLocationButtonEnabled(true);
    mAMap.setMyLocationEnabled(true);

    mAMap.setOnCameraChangeListener(new MyOnCameraChangeListener());
    mAMap.setOnMapLoadedListener(new MyOnMapLoadedListener());

    mGeocodeSearch = new GeocodeSearch(getApplicationContext());
    mGeocodeSearch.setOnGeocodeSearchListener(new MyOnGeocodeSearchListener());

    // 请求权限
    PermissionUtil.requestPermissions(this,
            new String[] {
                    Manifest.permission.WRITE_EXTERNAL_STORAGE,
                    Manifest.permission.ACCESS_FINE_LOCATION},
            99);
}
 
示例6
@Override
public void onMethodCall(MethodCall methodCall, MethodChannel.Result result) {
    geocoderSearch = new GeocodeSearch(FlutterAmapPlugin.registrar.activity().getApplicationContext());
    geocoderSearch.setOnGeocodeSearchListener(this);
    if (methodCall.method.equals("geoToCoordinate")) {
        if (methodCall.arguments instanceof String) {
            geoConvertToCoordinate(methodCall.arguments.toString());
        }
    } else if (methodCall.method.equals("coordinateToGeo")) {
        if (methodCall.arguments instanceof String) {
            Coordinate model = new Gson().fromJson(methodCall.arguments.toString(), Coordinate.class);
            coordinateConvertToGeo(model);
        }
    }
}
 
示例7
/**
 * 初始化AMap对象
 */
private void init() {
	if (aMap == null) {
		aMap = mapView.getMap();
		geoMarker = aMap.addMarker(new MarkerOptions().anchor(0.5f, 0.5f)
				.icon(BitmapDescriptorFactory
						.defaultMarker(BitmapDescriptorFactory.HUE_BLUE)));
	}
	Button geoButton = (Button) findViewById(R.id.geoButton);
	geoButton.setText("GeoCoding(北京市朝阳区方恒国际中心A座)");
	geoButton.setOnClickListener(this);
	geocoderSearch = new GeocodeSearch(this);
	geocoderSearch.setOnGeocodeSearchListener(this);
	progDialog = new ProgressDialog(this);
}
 
示例8
/**
 * 响应逆地理编码
 */
public void getAddress(final LatLonPoint latLonPoint) {
	showDialog();
	RegeocodeQuery query = new RegeocodeQuery(latLonPoint, 200,
			GeocodeSearch.AMAP);// 第一个参数表示一个Latlng,第二参数表示范围多少米,第三个参数表示是火系坐标系还是GPS原生坐标系
	geocoderSearch.getFromLocationAsyn(query);// 设置异步逆地理编码请求
}
 
示例9
@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);
}
 
示例10
/**
 * 由城市名查询地理位置
 * @param address 地址
 * @param name 城市名字
 */
private void doSearchGeo(String address, String name) {
    GeocodeSearch geocoderSearch = new GeocodeSearch(getContext());
    geocoderSearch.setOnGeocodeSearchListener(this);
    GeocodeQuery query = new GeocodeQuery(address, name);
    geocoderSearch.getFromLocationNameAsyn(query);
}
 
示例11
public AmapWrapper(AMap aMap){
    this.mAmap = aMap;
    mAmapStateListener = new AMapStateListenerImpl();
    mGeocodeSearch = new GeocodeSearch(GlobalApplication.getAppContext());
    mMapDrawer = new MapDrawer(mAmap);
    initLocationOptions();
    initLocationClient();
}
 
示例12
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);
}
 
示例13
@Override
public void onCameraChangeFinish(CameraPosition cameraPosition) {
    LatLonPoint point = new LatLonPoint(cameraPosition.target.latitude, cameraPosition.target.longitude);
    RegeocodeQuery query = new RegeocodeQuery(point, 50, GeocodeSearch.AMAP);
    geocodeSearch.getFromLocationAsyn(query);
    if (centerMarker != null) {
        animMarker();
    }
    showLocationView();
}
 
示例14
@Override
public void onCameraChangeFinish(CameraPosition cameraPosition) {
    LatLonPoint point = new LatLonPoint(cameraPosition.target.latitude, cameraPosition.target.longitude);
    RegeocodeQuery query = new RegeocodeQuery(point, 50, GeocodeSearch.AMAP);
    geocodeSearch.getFromLocationAsyn(query);
    if (centerMarker != null) {
        animMarker();
    }
    showLocationView();
}
 
示例15
@Override
protected void onCreate(WriteActivity view, Bundle savedState) {
    super.onCreate(view, savedState);
    provider = new ImageProvider(getView());
    mGeocoderSearch = new GeocodeSearch(getView());
    mGeocoderSearch.setOnGeocodeSearchListener(this);
    location = LocationModel.getInstance().getCurLocation();
    if (location != null) {
        mGeocoderSearch.getFromLocationAsyn(new RegeocodeQuery(new LatLonPoint(location.getLatitude(), location.getLongitude()), 50, GeocodeSearch.AMAP));
    }
}
 
示例16
private void initMyPoint() {
    Location location = LocationModel.getInstance().getCurLocation();
    moveTo(location.getLatitude(), location.getLongitude(), 13);
    mGeocoderSearch.getFromLocationAsyn(new RegeocodeQuery(new LatLonPoint(location.getLatitude(), location.getLongitude()), 50, GeocodeSearch.AMAP));

    MarkerOptions markerOption = new MarkerOptions();
    markerOption.icon(BitmapDescriptorFactory
            .fromResource(R.drawable.location_marker));
    mMyLocation = aMap.addMarker(markerOption);
    mPoint = new LatLng(location.getLatitude(),location.getLongitude());
    LocationModel.getInstance().registerLocationChange(newLocation -> mMyLocation.setPosition(new LatLng(location.latitude,location.longitude)));
}
 
示例17
@Override
public void onMapClick(LatLng latLng) {
    if (mLastMarker != null) mLastMarker.destroy();
    mPoint = latLng;
    MarkerOptions markerOption = new MarkerOptions();
    markerOption.position(latLng);
    markerOption.icon(BitmapDescriptorFactory
            .fromResource(R.drawable.location_point_bigger_red));
    mLastMarker = aMap.addMarker(markerOption);
    mGeocoderSearch.getFromLocationAsyn(new RegeocodeQuery(new LatLonPoint(latLng.latitude,latLng.longitude), 50,GeocodeSearch.AMAP));
}
 
示例18
@Override
public boolean onMarkerClick(Marker marker) {
    if (marker.equals(mMyLocation)){
        if (mLastMarker != null) mLastMarker.destroy();
        mPoint = marker.getPosition();
        mGeocoderSearch.getFromLocationAsyn(new RegeocodeQuery(new LatLonPoint(marker.getPosition().latitude,marker.getPosition().longitude), 50,GeocodeSearch.AMAP));
    }
    return true;
}
 
示例19
private void coordinateConvertToGeo(Coordinate coordinate) {
    RegeocodeQuery query = new RegeocodeQuery(new LatLonPoint(coordinate.latitude, coordinate.longitude), 200, GeocodeSearch.AMAP);
    geocoderSearch.getFromLocationAsyn(query);
}
 
示例20
private void searchLocationsName(LatLng latLng) {
    oldLocation = latLng;
    LatLonPoint point = new LatLonPoint(latLng.latitude, latLng.longitude);
    RegeocodeQuery query = new RegeocodeQuery(point, 1000, GeocodeSearch.AMAP);
    geocodeSearch.getFromLocationAsyn(query);
}
 
示例21
public RegeocodeTask(Context context) {
	mGeocodeSearch = new GeocodeSearch(context);
	mGeocodeSearch.setOnGeocodeSearchListener(this);
}
 
示例22
public void search(double latitude, double longitude) {
	RegeocodeQuery regecodeQuery = new RegeocodeQuery(new LatLonPoint(
			latitude, longitude), SEARCH_RADIUS, GeocodeSearch.AMAP);
	mGeocodeSearch.getFromLocationAsyn(regecodeQuery);
}
 
示例23
private void geocodeAddress() {

        if (mSearchLatLonPoint == null) return;

        RegeocodeQuery query = new RegeocodeQuery(mSearchLatLonPoint, 2000, GeocodeSearch.AMAP);
        mGeocodeSearch.getFromLocationAsyn(query);
    }