我想将标记固定在地图的中心,而不管位置坐标如何。如果用户在地图上移动相机,我希望它继续显示在中心而没有任何闪烁的标记和该标记上的新位置显示,我该怎么做?请帮忙。
答案 0 :(得分:3)
尝试以下目标C代码
不要忘记设置代表
mapView.delegate=self;
创建ImageView并将其添加到地图中心
UIImageView *pin =[[UIImageView alloc]init];
pin.frame=CGRectMake(0, 0, 20, 20 );
pin.center = mapView.center;
pin.image = [UIImage imageNamed:@"location.png"];
[self.view addSubview:pin];
[self.view bringSubviewToFront:pin];
然后使用谷歌地图的委托方法
//When You Will Scroll Map Then This Method Will Be Called
- (void)mapView:(GMSMapView *)MapView didChangeCameraPosition:(GMSCameraPosition *)position {
// Get Latitude And Longitude Of Your Pin(ImageView)
CLLocationCoordinate2D newCoords = CLLocationCoordinate2DMake( position.target.latitude , position.target.longitude);
NSLog(@"Latitude-%f\Longitude-%f\n",newCoords.latitude, newCoords.longitude);
[[GMSGeocoder geocoder] reverseGeocodeCoordinate:CLLocationCoordinate2DMake(newCoords.latitude, newCoords.longitude) completionHandler:^(GMSReverseGeocodeResponse* response, NSError* error) {
//Get Place Details
NSLog(@"%@",[[response results]objectAtIndex:0].lines);
}];
return;
}
答案 1 :(得分:2)
不移动标记
根据GMSMapView的框架在GMSMapView的中心创建一个Imageview或Button(如果可单击)。
如果您想获得坐标,可以使用mapView.projection.coordinateForPoint
这将移动标记
按照以下代码
查找谷歌地图的中心点let centerCord = yourMapView.camera.target
let marker = GMSMarker(position: centerCord)
marker.title = "Hello World"
marker.map = mapView
实现mapView:didChangeCameraPosition:
func mapView(mapView: GMSMapView, didChangeCameraPosition position: GMSCameraPosition) {
// to remove all markers
mapView.clear()
//create new marker with new center
let centerCord = [yourMapView.camera target]
let marker = GMSMarker(position: centerCord)
marker.title = "Hello World"
marker.map = mapView
}
答案 2 :(得分:2)
请尝试以下代码
--use 120s, 18 million data
explain SELECT DISTINCT d.taid
FROM tvassist_recommend_list_everyday_diverse d, tvassist_taid_all t
WHERE d.taid = t.taid
AND t.client_version >= '21004007'
AND t.utdid IS NOT NULL
AND d.recommend_day = '20170403'
LIMIT 0, 10000
--use 3.6s repalce by straight join
explain SELECT DISTINCT d.taid
FROM tvassist_recommend_list_everyday_diverse d
STRAIGHT_JOIN
tvassist_taid_all t on d.taid = t.taid
WHERE
t.client_version >= '21004007'
AND d.recommend_day = '20170403'
AND t.utdid IS NOT NULL
LIMIT 0, 10000