我已经给出了苹果 map 的替代方案,称为谷歌地图。此问答提供了如何创建谷歌地图并在 map 上创建带有描述的标记的解决方案。
最佳答案
首先完成此链接 https://developers.google.com/maps/documentation/ios/start 中列出的步骤
创建 map 的代码。
CLLocationCoordinate2D coordinate = [self getLocation]; GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:coordinate.latitude longitude:coordinate.longitude zoom:15]; mapView = [GMSMapView mapWithFrame:CGRectMake(0, 0, 320, 120) camera:camera]; [mapView animateToCameraPosition:camera]; mapView.delegate = self; mapView.myLocationEnabled = YES; [self.view addSubview:mapView]; //getlocation method -(CLLocationCoordinate2D) getLocation{ CLLocationManager *locationManager = [[[CLLocationManager alloc] init] autorelease]; locationManager.delegate = self; locationManager.desiredAccuracy = kCLLocationAccuracyBest; locationManager.distanceFilter = kCLDistanceFilterNone; [locationManager startUpdatingLocation]; CLLocation *location = [locationManager location]; CLLocationCoordinate2D coordinate = [location coordinate]; return coordinate; }
正在为 map 上的当前位置创建标记。
[[GMSGeocoder geocoder] reverseGeocodeCoordinate:CLLocationCoordinate2DMake(coordinate.latitude,coordinate.longitude) completionHandler:^(GMSReverseGeocodeResponse *response, NSError *error) { NSLog( @"Error is %@", error) ; NSLog( @"%@" , response.firstResult.addressLine1 ) ; NSLog( @"%@" , response.firstResult.addressLine2 ) ; GMSMarker *marker = [[GMSMarker alloc] init]; marker.position = coordinate; marker.title = response.firstResult.addressLine1; marker.snippet = response.firstResult.addressLine2; marker.appearAnimation = kGMSMarkerAnimationPop; NSArray* parts = [response.firstResult.addressLine2 componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@","]]; locValueLabel.text = [parts objectAtIndex:0]; marker.map = mapView; } ] ;
关于ios - 为 iOS 实现 Google map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20376357/