我是iOS新手,面臨着在Google地圖上創建多個引腳的問題。 我的代碼是這樣的如何在Google地圖上動態創建多個引腳,目標爲C
在View DidLoad()
//Google Maps...
_placesClient = [GMSPlacesClient sharedClient];
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:18.516726
longitude:73.856255
zoom:3];
mapView = [GMSMapView mapWithFrame:CGRectMake(10, 140, 350, 350) camera:camera];
GMSMutablePath *path = [GMSMutablePath path];
[path addLatitude:18.516726 longitude:73.856255]; // Sydney
[path addLatitude:19.0728300 longitude:72.8826100]; // Fiji
mapView.delegate=self;
mapView.myLocationEnabled=YES;
locationtbl.hidden=YES;
if (nil == locationManager)
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
//Configure Accuracy depending on your needs, default is kCLLocationAccuracyBest
locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;
// Set a movement threshold for new events.
locationManager.distanceFilter = 500; // meters
[locationManager startUpdatingLocation];
mapView.settings.myLocationButton = YES;
mapView.settings.scrollGestures = YES;
mapView.settings.zoomGestures = YES;
mapView.settings.tiltGestures=YES;
mapView.settings.rotateGestures=NO;
mapView.settings.compassButton = YES;
[self.view addSubview:mapView];
谷歌委託的方法是這樣的
#pragma mark - Google Maps
// Add a UIButton in Interface Builder to call this function
- (IBAction)pickPlace:(UIButton *)sender {
CLLocationCoordinate2D center = CLLocationCoordinate2DMake(18.516726, 73.856255);
CLLocationCoordinate2D northEast = CLLocationCoordinate2DMake(center.latitude + 0.001,
center.longitude + 0.001);
CLLocationCoordinate2D southWest = CLLocationCoordinate2DMake(center.latitude - 0.001,
center.longitude - 0.001);
GMSCoordinateBounds *viewport = [[GMSCoordinateBounds alloc] initWithCoordinate:northEast
coordinate:southWest];
GMSPlacePickerConfig *config = [[GMSPlacePickerConfig alloc] initWithViewport:viewport];
_placePicker = [[GMSPlacePicker alloc] initWithConfig:config];
[_placePicker pickPlaceWithCallback:^(GMSPlace *place, NSError *error) {
if (error != nil) {
NSLog(@"Pick Place error %@", [error localizedDescription]);
return;
}
if (place != nil) {
self.nameLabel.text = place.name;
self.addressLabel.text = [[place.formattedAddress
componentsSeparatedByString:@", "] componentsJoinedByString:@"\n"];
} else {
self.nameLabel.text = @"No place selected";
self.addressLabel.text = @"";
}
}];
}
我現在面臨的問題是如何顯示在谷歌地圖多個引腳。我從數組中的動態Web服務中獲得價值。我需要在谷歌地圖上顯示針腳,像這樣圖片
H是在谷歌地圖上創建的圖像,這是Image.How做到這一點??
我用這樣的代碼
for (int i=0; i<NameHSArray.count; i++) {
CLLocationCoordinate2D position = CLLocationCoordinate2DMake(18.516726, 73.856255);
GMSMarker *marker = [GMSMarker markerWithPosition:position];
marker.title = @"Hello World";
marker.icon = [UIImage imageNamed:@"mapicon1.png"];
marker.map = mapView;
}
但是,當我加入陣列它給我前進誤差
謝謝!
我用這個代碼,並對其做
for (int i=0; i<NameHSArray.count; i++) {
double LatitudeDouble = [LatitudeHSArray[i] doubleValue];
double LongitudeDouble = [LongitudeHSArray[i] doubleValue];
CLLocationCoordinate2D position = CLLocationCoordinate2DMake(LatitudeDouble, LongitudeDouble);
GMSMarker *marker = [GMSMarker markerWithPosition:position];
marker.title = NameHSArray[i];
marker.icon = [UIImage imageNamed:@"mapicon1.png"];
GMSCameraUpdate *zoomCamera = [GMSCameraUpdate zoomIn];
[mapView animateWithCameraUpdate:zoomCamera];
marker.map = mapView;
}
字符串值在陣列中試試這[[LattitudeHSArray objectAtIndex:0] doubleValue] double value in array然後使用[LattitudeHSArray objectAtIndex:0] 試試這個 –