最开始附上我的初始化参数。
private MapView mapView;
private AMap aMap;
private ToggleButton btn_mapchange;
private MyLocationStyle myLocationStyle;
private LocationSource.OnLocationChangedListener mListener;
private AMapLocationClient locationClient;
private AMapLocationClientOption clientOption;
private GeocodeSearch geocodeSearch;
private double latitude;
private double longtitude;
一、自定义地图中心点
mapView= (MapView) view.findViewById(R.id.map);
mapView.onCreate(savedInstanceState);
if (aMap==null)
{
aMap=mapView.getMap();
}
LatLng marker1 = new LatLng(30.53786, 114.365248);
//设置中心点和缩放比例
aMap.moveCamera(CameraUpdateFactory.changeLatLng(marker1));
aMap.moveCamera(CameraUpdateFactory.zoomTo(12));
二、通过输入地理位置获得经纬度
1、实现 GeocodeSearch.OnGeocodeSearchListener接口
2、在重写的方法中写如下代码
@Override
public void onRegeocodeSearched(RegeocodeResult regeocodeResult, int i) {
}
//回调函数
@Override
public void onGeocodeSearched(GeocodeResult geocodeResult, int i) {
//判断请求是否成功(1000为成功,其他为失败)
if (i == 1000) {
if (geocodeResult != null && geocodeResult.getGeocodeAddressList() != null
&& geocodeResult.getGeocodeAddressList().size() > 0) {
GeocodeAddress address = geocodeResult.getGeocodeAddressList().get(0);
Log.i("TAG_MAIN", "经纬度值:" + address.getLatLonPoint() + "位置描述:"
+ address.getFormatAddress());
}
}
}
3、实例化GeocodeSearch,调用如下方法
geocodeSearch = new GeocodeSearch(this.getContext());
geocodeSearch.setOnGeocodeSearchListener(this);
//通过 GeocodeQuery(java.lang.String locationName, java.lang.String city) 设置查询参数,调用 GeocodeSearch 的 getFromLocationNameAsyn(GeocodeQuery geocodeQuery) 方法发起请求
GeocodeQuery query = new GeocodeQuery("武汉大学", "武汉");
//发起请求
geocodeSearch.getFromLocationNameAsyn(query);
三、定位
这个最简单,直接去网上搜吧,一大堆。我这里就不做重复了