高德地圖逆地理編碼
1. android高德地圖怎麼發送位置信息
Android 開發過程中,有很多手勢操作都很讓人又愛又恨。一方面可以更便捷的體現更多功能,提升應用的體驗,一方面繁復多變的操作背後有著許多開發技巧和難題。這里分享一個長按地圖獲取位置信息的手勢。
為了更明了,先上個展示效果:長按地圖某點顯示該點地理位置信息功能
通過構造一個locationSelectOverlay類來定義該功能,在地圖上對長按手勢進行監聽,一旦有這個事件發生就調用getAddressFromServer()方法來顯示地址信息。
在該工程中分別定義4個類longPressMap.java,locationSelectOverlay.java,popUpPanel.java,Constants.javalongPressMap.java 為顯示一個地圖類,通過實例化一個locationSelectOverlay類實現長按地圖顯示地理位置信息功能代碼如下:
//longPressMap 類繼承MapActivity對mapview資源進行管理
public class longPressMap extends MapActivity {
private MapView mMapView;
locationSelectOverlay mSelectLay;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//使用setContentView方法調用R.layout.activity_regeocoder布局文件,顯示地圖
setContentView(R.layout.geocoder);
//獲取地圖視圖的id,賦值給mMapView
mMapView = ((MapView) findViewById(R.id.geocode_MapView));
// 設置啟用內置的縮放控制項
mMapView.setBuiltInZoomControls(true);
//實例化一個locationSelectOverlay類
mSelectLay = new locationSelectOverlay(this, mMapView, new popUpPanel(this, mMapView));
//將該功能載入到此地圖上,啟用長按地圖顯示該點地址信息的功能
mMapView.getOverlays().add(mSelectLay);
}
}
復制代碼
locationSelectOverlay 示例代碼如下:
//locationSelectOverlay類繼承Overlay介面,實現OnGestureListener手勢監聽
public class locationSelectOverlay extends Overlay implements OnGestureListener {
public popUpPanel mTipPanel; //聲明一個彈出框對象
GeoPoint mSelectPoint; //聲明一個地理坐標點對象
MapView mMapView; //聲明一個地圖視圖對象
Context mContext; //活動對象
TextView mTipText=null; //聲明一個文本對象
private static String nearbystr="";
private GestureDetector gestureScanner; //聲明一個手勢監聽對象
private Geocoder coder; //聲明一個逆地理編碼對象
private String addressName=""; //聲明一個地址名稱字元串
//長按地圖某點獲取信息的構造函數。
public locationSelectOverlay(Activity context,MapView mapView,popUpPanel panel)
{
this.mContext=context;
this.mMapView=mapView;
this.mTipPanel=panel;
gestureScanner = new GestureDetector(this); //聲明一個手勢監聽對象
coder = new Geocoder(context); //聲明一個逆地理編碼對象
}
//用Handler函數處理傳遞來的地址信息,顯示在文本框中
private Handler mGeocoderHandler = new Handler()
{
public void handleMessage(Message msg)
{
//如果有地址信息的消息發送過來,將文本框中設置為該地址信息
if(msg.what == Constants.REOCODER_RESULT)
{
if(mTipText!=null)
mTipText.setText(addressName);
}
//如果顯示錯誤,則文本框中設置報錯信息
else if(msg.what == Constants.ERROR)
{
Toast.makeText(mContext, "獲取地址失敗,請重試", Toast.LENGTH_SHORT).show();
removeTipPanel();
}
}
};
//顯示彈出窗口
public boolean showTap(GeoPoint p) {
View view = mTipPanel.getView();
mMapView.removeView(view);
//布局參數設置
MapView.LayoutParams geoLP = new MapView.LayoutParams(
MapView.LayoutParams.WRAP_CONTENT,
MapView.LayoutParams.WRAP_CONTENT, p,
MapView.LayoutParams.BOTTOM_CENTER);
//彈出窗口的文本顯示
mTipText = (TextView) view.findViewById(R.id.GeoName);
mTipText.setText("正在載入地址...");
mTipText.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
}
});
//在地圖視圖上添加該彈出窗口視圖
mMapView.addView(view, geoLP);
return false;
}
//從經緯度坐標點獲取對應的地址信息
public void getAddressFromServer(final GeoPoint point,final Handler handler)
{
//聲明一個線程
new Thread(){
public void run()
{
try {
// 逆地理編碼getFromLocation()函數獲取該點對應的前3個地址信息
List<Address> address = coder.getFromLocation((double)point.getLatitudeE6()/1E6,
(double)point.getLongitudeE6()/1E6, 3);
if (address != null) {
//獲取第一個地址信息
Address addres = address.get(0);
addressName = "";
if(addres.getAdminArea()!=null)
addressName+=addres.getAdminArea();
if(addres.getSubLocality()!=null)
addressName += addres.getSubLocality();
if(addres.getFeatureName()!=null)
addressName += addres.getFeatureName();
addressName += "附近";
handler.sendMessage(Message
.obtain(handler, Constants.REOCODER_RESULT));
}
} catch (AMapException e) {
// TODO Auto-generated catch block
handler.sendMessage(Message
.obtain(handler, Constants.ERROR));
}
}
}.start(); //線程啟動
}
//移走彈出窗口
public void removeTipPanel()
{
View view = mTipPanel.getView();
mMapView.removeView(view);
}
//獲取手勢操作
public boolean onTouchEvent(MotionEvent event, MapView mapView)
{
return gestureScanner.onTouchEvent(event);
}
@Override
public boolean onDown(MotionEvent e) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
// TODO Auto-generated method stub
return false;
}
//長按地圖,彈出提示框,顯示該點地址信息
@Override
public void onLongPress(MotionEvent e) {
// TODO Auto-generated method stub
int x = (int)e.getX();
int y = (int)e.getY();
mSelectPoint = mMapView.getProjection().fromPixels(x, y);
//調用顯示提示框函數
showTap(mSelectPoint);
//調用從經緯度點獲取地址信息函數
getAddressFromServer(mSelectPoint,mGeocoderHandler);
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
float distanceY) {
// TODO Auto-generated method stub
return false;
}
復制代碼
pouUpPanel定義了彈出窗口類
public class popUpPanel
{
private boolean isVisible = false;
private MapView mMapView;
private View popup;
public popUpPanel(Activity paramActivity, MapView paramMapView)
{
this.mMapView = paramMapView;
ViewGroup localViewGroup = (ViewGroup)this.mMapView.getParent();
//設置彈出的視圖是id為R.layout.activity_long_press_map的視圖
this.popup = paramActivity.getLayoutInflater().inflate(R.layout.activity_long_press_map, localViewGroup, false);
…
復制代碼
Constants
定義了傳遞的常量對應的值,如public static finalint REOCODER_RESULT=3000; 表示逆地理編碼結果常量,public staticfinal int ERROR=1001; 表示出現錯誤常量。
2. 高德地圖的API怎麼用URL實現地理編碼/逆地理編碼
API的相關問題有兩種咨詢求助的解決方式:
1、官方API論壇發帖
http://bbs.amap.com/forum.php?gid=1
2、或者發送郵件到專官方郵箱屬:[email protected]
3. 高德地圖逆地理編碼結果沒有數據,是什麼問題
我利用CoreLocatio下的locManager=[[CLLocationManageralloc]init];//locManager.delegate=self;//locManager.desiredAccuracy=kCLLocationAccuracyBest;//locManager.distanceFilter=5.0f;//[];方法獲取當前位置的經緯回度,然後用答MASearch*maSearch=[[MASearchalloc]init];*searchOption=[[alloc]init];searchOption.config=@"SPAS";searchOption.x=self.klatitude;searchOption.y=self.klongitude;[:searchOption]
4. 高德地圖逆地理編碼的的回調函數加什麼東西嗎
建議到高德社區API專區咨詢
5. 高德api地理編碼和逆地理編碼問題
我利用CoreLocatio下的locManager=[[CLLocationManager alloc]init];
// locManager.delegate=self;
// locManager.desiredAccuracy=kCLLocationAccuracyBest;
// locManager.distanceFilter=5.0f;
// [locManager startUpdatingLocation];
方法獲取當前位置的經緯度,然後用
MASearch *maSearch=[[MASearch alloc]init];
*searchOption=[[ alloc]init];
searchOption.config=@"SPAS";
searchOption.x=self.klatitude;
searchOption.y=self.klongitude;
[maSearch :searchOption]
不要多想 這樣的提問沒有意義
很多煩惱都是我們自己找的
6. 高德地圖逆地理編碼的的回調函數加什麼東西嗎
我利用CoreLocatio下的locManager=[[CLLocationManager alloc]init];
// locManager.delegate=self;
// locManager.desiredAccuracy=kCLLocationAccuracyBest;
// locManager.distanceFilter=5.0f;
// [locManager startUpdatingLocation];
方法獲取當前位置的經緯度,然後用
MASearch *maSearch=[[MASearch alloc]init];
*searchOption=[[ alloc]init];
searchOption.config=@"SPAS";
searchOption.x=self.klatitude;
searchOption.y=self.klongitude;
[maSearch :searchOption]
7. 高德地圖逆地理編碼結果沒有數據,是什麼問題
樓主好:請問是開發問題嗎?開發問題小德是技術小白,建議您到開放平台創建工單咨詢下技術人員哦!
8. 高德地圖怎樣實現實時定位,得到當前地點的坐標,位置
我的程序沒有回調 -(void)reverseGeocodingSearch:(*)geoCodingSearchOption Result:(*)result方法?這個是高德地圖里的逆地理查詢的回調函數。
具體說明:我利用CoreLocatio下的locManager=[[CLLocationManager alloc]init];
// locManager.delegate=self;
// locManager.desiredAccuracy=kCLLocationAccuracyBest;
// locManager.distanceFilter=5.0f;
// [locManager startUpdatingLocation];
方法獲取當前位置的經緯度,然後用
MASearch *maSearch=[[MASearch alloc]init];
*searchOption=[[ alloc]init];
searchOption.config=@"SPAS";
searchOption.x=self.klatitude;
searchOption.y=self.klongitude;
[maSearch :searchOption];方法逆地理編碼獲取當前城市的名字
9. 高德地圖逆地理編碼結果沒有數據,是什麼問題
框架:MapKit.framework,CoreLocation.framework兩個足矣添加地圖就不說了,用CoreLocation.framework裡面的CLGeocoder類,進行轉換可用的函數下面三個:-(void)geocodeAddressDictionary:(NSDictionary*):(CLGeocodeCompletionHandler)completionHandler;-(void)geocodeAddressString:(NSString*):(CLGeocodeCompletionHandler)completionHandler;-(void)geocodeAddressString:(NSString*)addressStringinRegion:(CLRegion*)regioncompletionHandler:(CLGeocodeCompletionHandler)completionHandler;(這三個函數的用法就不說了,一搜一堆)可以得到地理位置,然後地圖設置一下center或者region就OK了
10. js sdk高德地圖逆地理編碼api服務地址怎麼用
我利用下的locManager=[[CLLocationManager alloc]init];
// locManager.delegate=self;
// locManager.desiredAccuracy=kCLLocationAccuracyBest;
// locManager.distanceFilter=5.0f;
// [locManager startUpdatingLocation];
方法獲取當前位置的經緯度,然後用
MASearch *maSearch=[[MASearch alloc]init];
*searchOption=[[ alloc]init];
searchOption.config=@"SPAS";
searchOption.x=self.klatitude;
searchOption.y=self.klongitude;
[maSearch :searchOption]
不要多想 這樣的提問沒有意義
很多煩惱都是我們自己找的