创建浮动标记Google Maps iOS
有没有办法创建一个浮动标记,可以选择它的位置,但保持在它的中心视图,并且它的地图可以滚动? 我找到了javascript版本 函数初始化{ var crosshairShape={ 坐标:[0,0,0,0], 类型:“rect” }; var latlng=new google.maps.LatLng54.62279178711505,-5.895538330078125; 变量myOptions={ 缩放:12, 中心:拉特林, mapTypeId:google.maps.mapTypeId.SATELLITE, mapTypeControlOptions:{ 样式:google.maps.MapTypeControlStyle.DROPDOWN_菜单 } }; var map=new google.maps.Mapdocument.getElementByIdmap_画布,myOptions; var marker=new google.maps.marker{ 地图:地图, }; document.getElementById'coordinates'.innerHTML=中心坐标:+map.getCenter.toUrlValue6 google.maps.event.addListenermap,“中心已更改”,函数{ document.getElementById'coordinates'.innerHTML=中心坐标:+map.getCenter.toUrlValue6; }; 标记。绑定到“位置”,映射到“中心”; } google.maps.event.AddDomainListenerWindow“加载”,初始化; html, 身体 地图画布{ 高度:500px; 宽度:500px; 边际:0px; 填充:0px }创建浮动标记Google Maps iOS,ios,objective-c,google-maps,google-maps-markers,Ios,Objective C,Google Maps,Google Maps Markers,有没有办法创建一个浮动标记,可以选择它的位置,但保持在它的中心视图,并且它的地图可以滚动? 我找到了javascript版本 函数初始化{ var crosshairShape={ 坐标:[0,0,0,0], 类型:“rect” }; var latlng=new google.maps.LatLng54.62279178711505,-5.895538330078125; 变量myOptions={ 缩放:12, 中心:拉特林, mapTypeId:google.maps.mapTypeId
我不会全部写出来,但是: 一点也不要用记号笔;只需使用添加为地图子视图的普通UIView即可。。居中
而中心坐标就是可见区域的中心坐标我不会全部写出来,但是: 一点也不要用记号笔;只需使用添加为地图子视图的普通UIView即可。。居中
而中心坐标只是可见区域的中心坐标,下面的代码应该可以帮助您
// Call this function from -viewdidload with valid GMSMapView input.
- (UIImageView *)addMarkerOnMapViewCenter:(GMSMapView *)mapView
{
UIView *vwMapParentView = mapView.superview;
UIImageView *vwMarker = [UIImageView new];
[vwMarker setFrame:(CGRect){0,0,20,40}];
// Customize the Background color as per your need.
[vwMarker setBackgroundColor:[UIColor greenColor]];
// Drop an icon named markerIcon.png in your project bundle
[vwMarker setImage:[UIImage imageNamed:@"markerIcon.png"]];
[vwMarker setCenter:(CGPoint){vwMapParentView.center.x,(vwMapParentView.center.y - vwMarker.frame.size.height)}]; // if needed subtract navigation bar height as well as per the requirement.
[vwMapParentView addSubview:vwMarker];
[vwMapParentView bringSubviewToFront:vwMarker];
return vwMarker;
}
// And then,Implement this GMSMapView's delegate method.
- (void)mapView:(GMSMapView *)mapView didChangeCameraPosition:(GMSCameraPosition *)position
{
CLLocationCoordinate2D target = position.target;
NSLog(@"%f : %f",target.latitude,target.longitude);
}
希望有帮助
谢谢,纳雷什。下面的代码应该可以帮助您
// Call this function from -viewdidload with valid GMSMapView input.
- (UIImageView *)addMarkerOnMapViewCenter:(GMSMapView *)mapView
{
UIView *vwMapParentView = mapView.superview;
UIImageView *vwMarker = [UIImageView new];
[vwMarker setFrame:(CGRect){0,0,20,40}];
// Customize the Background color as per your need.
[vwMarker setBackgroundColor:[UIColor greenColor]];
// Drop an icon named markerIcon.png in your project bundle
[vwMarker setImage:[UIImage imageNamed:@"markerIcon.png"]];
[vwMarker setCenter:(CGPoint){vwMapParentView.center.x,(vwMapParentView.center.y - vwMarker.frame.size.height)}]; // if needed subtract navigation bar height as well as per the requirement.
[vwMapParentView addSubview:vwMarker];
[vwMapParentView bringSubviewToFront:vwMarker];
return vwMarker;
}
// And then,Implement this GMSMapView's delegate method.
- (void)mapView:(GMSMapView *)mapView didChangeCameraPosition:(GMSCameraPosition *)position
{
CLLocationCoordinate2D target = position.target;
NSLog(@"%f : %f",target.latitude,target.longitude);
}
希望有帮助
谢谢,纳雷什。如前所述,不要添加为标记。只需使用普通UIView/UIImageView添加作为地图的子视图即可。然后实现以下代码Google maps didChangeCameraPosition或idleAtCameraPosition委托:
- (void) mapView:(GMSMapView *)mapView idleAtCameraPosition:(GMSCameraPosition *)position
{
CGPoint point = mapView.center;
CLLocationCoordinate2D coor = [mapView.projection coordinateForPoint:point];
}
如前所述,不要添加为标记。只需使用普通UIView/UIImageView添加作为地图的子视图即可。然后实现以下代码Google maps didChangeCameraPosition或idleAtCameraPosition委托:
- (void) mapView:(GMSMapView *)mapView idleAtCameraPosition:(GMSCameraPosition *)position
{
CGPoint point = mapView.center;
CLLocationCoordinate2D coor = [mapView.projection coordinateForPoint:point];
}
我会在MapView的中心添加一个图像,并在用户停止滚动时获取其坐标 要创建ImageView,请执行以下操作:
UIImageView *pin = [[UIImageView alloc] initWithFrame(0,0,10,10)];
pin.center = self.view.center;
pin.image = [UIImage imageNamed:@"pin"];
[self.view addSubview:pin];
[self.view bringSubviewToFront:pin];
要获取坐标,请执行以下操作:
-(void)mapView:(GMSMapView *)mapView idleAtCameraPosition:(GMSCameraPosition *)position
{
CGPoint point = pin.center;
CLLocationCoordinate2D coor = [mapView.projection coordinateForPoint:point];
CGFloat longitude = coor.longitude;
CGFloat latitude = coor.latitude;
}
我会在MapView的中心添加一个图像,并在用户停止滚动时获取其坐标 要创建ImageView,请执行以下操作:
UIImageView *pin = [[UIImageView alloc] initWithFrame(0,0,10,10)];
pin.center = self.view.center;
pin.image = [UIImage imageNamed:@"pin"];
[self.view addSubview:pin];
[self.view bringSubviewToFront:pin];
要获取坐标,请执行以下操作:
-(void)mapView:(GMSMapView *)mapView idleAtCameraPosition:(GMSCameraPosition *)position
{
CGPoint point = pin.center;
CLLocationCoordinate2D coor = [mapView.projection coordinateForPoint:point];
CGFloat longitude = coor.longitude;
CGFloat latitude = coor.latitude;
}
太谢谢你了,@Daij-Djan!太谢谢你了,@Daij-Djan!