今天做到一個需求是傳入 經緯度,mapView 顯示 對應的點並標上標註,一開始一直在找 mapView updateUserLocation 類似的方法去傳入經緯度,未果。晚上回來了想想,不就是標註大頭針,然後把它作爲地圖的中心點顯示在地圖上。用setCenterCoordinate:
方法就可以了(高德地圖setCenterCoordinate:
)。哎,這麼簡單的問題還花費那麼長時間~可能是明天就過節了,有點小機動
update time: 2016/11/25
需求是在cell中顯示 指定位置的地圖位置,但地圖view不做任何響應時間,點擊cell,跳轉到地圖界面。
效果類似下圖:
此時有兩種方案:
第一:顯示百度地圖mapView
通過百度地圖的view添加大頭針,
/ 添加一個PointAnnotation
BMKPointAnnotation* annotation = [[BMKPointAnnotation alloc]init];
CLLocationCoordinate2D coor;
coor.latitude = [self.latitudeTF.text floatValue];
coor.longitude = [self.longitudeTF.text floatValue];
annotation.coordinate = coor;
// annotation.title = @"這裏是北京";
[self.mapView addAnnotation:annotation];
將大頭針放在地圖中心點,
[self.mapView setCenterCoordinate:coor animated:YES];
取消mapView的任何響應事件
self.mapView.gesturesEnabled = NO;
第二 :顯示一個imageView,通過請求百度地圖靜態圖片的接口,拿到 圖片data。
接口:http://api.map.baidu.com/staticimage
請求類型:GET
傳入參數:
center: 地圖中心點位置,參數可以爲經緯度座標或名稱。座標格式:lng<經度>,lat<緯度>,例如116.43213,38.76623。
zoom: 高清圖範圍[3, 18];低清圖範圍[3,19]
markers: 標註,可通過經緯度或地址/地名描述;多個標註之間用豎線分隔。
更多參數請訪問百度靜態圖片 或 靜態圖API
將拿回來的responseObject 直接附給imageView的image即可:
imageView.image = [UIImage imageWithData:responseObject];
總結:這兩種方法對比很明顯,第一種使用百度SDK Momery佔用 大並且代碼寫起來設置內容多,但是可以無限制次使用/天;第二種方便簡潔,而且Momery佔用小,代碼設置少,但是有限制每天的請求次數:
請求頻率:無限制
URL長度:2048
點標記的數量:50個
調用次數:默認限制爲100萬次/天,併發100qps
大家根據需求來使用吧。