如何在我的iOS应用程序中为Google地图创建多个标记? [英] How do I create multiple markers for google maps in my iOS app?

查看:124
本文介绍了如何在我的iOS应用程序中为Google地图创建多个标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm unable to find an answer as to how I place several markers on a google map in an iOS app. I know it can be done but I don't know how to do it. This is using some google documentation but my app will display NYC locations. Here's my very-wrong code: In GoogleMapsViewController.m I have the following code:

//  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


推荐答案

我找到了一种使它工作的方法。我只是以相同的格式添加位置。这里是我的代码:

I found a way to make it work. I simply added the location in the same format. Here's my code:

- (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应用程序中为Google地图创建多个标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆