gpt4 book ai didi

ios - 如何在我的 iOS 应用程序中为谷歌地图创建多个标记?

转载 作者:行者123 更新时间:2023-11-29 03:17:25 26 4
gpt4 key购买 nike

关于如何在 iOS 应用程序的谷歌地图上放置多个标记,我找不到答案。我知道可以做到,但我不知道该怎么做。这是使用一些谷歌文档,但我的应用程序将显示纽约市的位置。这是我非常错误的代码:在 GoogleMapsViewController.m 中,我有以下代码:

//  GoogleMapsViewController.m
// GoogleMaps1
//
// Created by Meghan on 2/1/14.
// Copyright (c) 2014 Meghan. All rights reserved.
//

#import "GoogleMapsViewController.h"
#import <GoogleMaps/GoogleMaps.h>

@interface GoogleMapsViewController ()

@end

@implementation GoogleMapsViewController {
GMSMapView *mapView_;
}

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
{
// Create a GMSCameraPosition that tells the map to display the
// coordinate -33.86,151.20 at zoom level 6.
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86
longitude:151.20
zoom:6];
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView_.myLocationEnabled = YES;
self.view = mapView_;

// Creates a marker in the center of the map (center for Sydney).

NSMutableArray *markersArray = [[NSMutableArray alloc] init];
for(int i=0;i<2;i++) {
id sydney = [markersArray objectAtIndex:0];
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake(-33.86, 151.20);
marker.title = @"Sydney";
marker.snippet = @"Australia";
marker.map = mapView_;

id newcastle = [markersArray objectAtIndex:1];
GMSMarker *marker1 = [[GMSMarker alloc] init];
marker1.position = CLLocationCoordinate2DMake(-32.92, 151.78);
marker1.title = @"Newcastle";
marker1.snippet = @"Australia";
marker1.map = mapView_;
}
}
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end

最佳答案

我找到了一种让它发挥作用的方法。我只是以相同的格式添加了位置。这是我的代码:

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
{
// Create a GMSCameraPosition that tells the map to display the
// coordinate -33.86,151.20 at zoom level 6.
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86
longitude:151.20
zoom:6];
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView_.myLocationEnabled = YES;
self.view = mapView_;

// Creates a marker in the center of the map.
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake(-33.86, 151.20);
marker.title = @"Sydney";
marker.snippet = @"Australia";
marker.map = mapView_;

GMSMarker *marker1 = [[GMSMarker alloc] init];
marker1.position = CLLocationCoordinate2DMake(-32.92, 151.78);
marker1.title = @"Newcastle";
marker1.snippet = @"Australia";
marker1.map = mapView_;
}
}

关于ios - 如何在我的 iOS 应用程序中为谷歌地图创建多个标记?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21531974/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com