作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在我的应用程序中使用谷歌地图 api。我的应用程序中有两个按钮。第一个按钮在我的 map 中添加了一个标记(图钉)。
现在我想要第二个按钮将添加的图钉水平移动到页面中心,并使其移动到页面顶部的 25%。我希望相机(用户正在查看的区域)也移动它。
这是我的代码:
@implementation ViewController
{
double latitudes;
double longitudes;
CLLocationManager *locationManager;
GMSMapView *mapView_;
}
- (void)viewDidLoad
{
[super viewDidLoad];
locationManager = [[CLLocationManager alloc] init];
[self GetMyLocation];
UIButton *pinButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
pinButton.frame = CGRectMake(self.view.frame.size.width-80,self.view.frame.size.height-80, 60, 60);
[pinButton setTitle:@"Self" forState:UIControlStateNormal];
[pinButton setBackgroundColor:[UIColor whiteColor]];
[pinButton addTarget:self action:@selector(ShowMyLocation:) forControlEvents:UIControlEventTouchUpInside];
UIButton *add = [UIButton buttonWithType:UIButtonTypeRoundedRect];
add.frame = CGRectMake(20,self.view.frame.size.height-80, 60, 60);
[add setTitle:@"add" forState:UIControlStateNormal];
[add setBackgroundColor:[UIColor whiteColor]];
[add addTarget:self action:@selector(Move:) forControlEvents:UIControlEventTouchUpInside];
// Create a GMSCameraPosition that tells the map to display the
// nokte mohem ine ke baadan ye logitude & latitude default ezafe kon chon shaiad tuie ye sharaiete tokhmi ke hamid esrar dare va ye kasi mariz bood dastresie GPS ro ghat kard
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:latitudes longitude:longitudes zoom:14];
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView_.myLocationEnabled = YES;
[mapView_ setMapType:kGMSTypeNormal];
self.view = mapView_;
[mapView_ addSubview:pinButton];
[mapView_ addSubview:add];
}
- (IBAction)Move:(id)sender{
//move marker place
}
- (IBAction)ShowMyLocation:(id)sender{
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake(coor.latitude,coor.longitude);
marker.title = @"I'm Here";
marker.snippet = @"Rahnova Co.";
marker.appearAnimation = kGMSMarkerAnimationPop;
marker.map = mapView_;
}
- (void) GetMyLocation{
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
}
#pragma mark - CLLocationManagerDelegate
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{
NSLog(@"didFailWithError: %@", error);
UIAlertView *errorAlert = [[UIAlertView alloc]
initWithTitle:@"Error" message:@"Failed to Get Your Location" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[errorAlert show];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{
CLLocation *currentLocation = newLocation;
if (currentLocation != nil) {
longitudes = currentLocation.coordinate.longitude;
latitudes = currentLocation.coordinate.latitude;
}
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:latitudes longitude:longitudes zoom:14];
[mapView_ animateToCameraPosition:camera];
}
最佳答案
试试这个代码: -
在您的 的标题上.M 实现文件,你必须实现 GMSMapViewDelegate .
@interface YourViewController ()<GMSMapViewDelegate>
mapView_.delegate=self;
-(BOOL)mapView:(GMSMapView *)mapView didTapMarker:(GMSMarker *)marker{
[mapView animateToLocation:marker.position];
return YES;
}
关于ios - 如何使用相机谷歌地图 xcode 移动标记(图钉),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23783642/
leaflet:一个开源并且对移动端友好的交互式地图 JavaScript 库 中文文档: https://leafletjs.cn/reference.html 官网(英文): ht
我是一名优秀的程序员,十分优秀!