在 ios 中的谷歌地图上添加多个图钉 [英] adding multiple pins on google map in ios

查看:57
本文介绍了在 ios 中的谷歌地图上添加多个图钉的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在加载谷歌地图时在其上添加多个图钉.

I want to add multiple pins on a google map, while it is being loaded.

我有附近位置的纬度和经度值列表.如何使用图钉在地图上显示所有这些位置.我使用的是 iOS 版 Google SDK.

I have a list of Latitude and Longitude values of nearby locations. How can I show all these locations on the map with a pin. I am using Google SDK for iOS.

我正在使用以下代码,但它对我不起作用.

I am using the following code, but it didn't work for me.

NSMutableArray *array = [NSMutableArray arrayWithObjects:@"12.981902,80.266333",@"12.982902,80.266363", nil];

CLLocationCoordinate2D pointsToUse[5];

for (int i = 0; i < [array Size]; i++)
{
    pointsToUse[i] = CLLocationCoordinate2DMake([[[[array objectAtIndex:0]  componentsSeparatedByString:@","] objectAtIndex:0] floatValue],[[[[array objectAtIndex:0]  componentsSeparatedByString:@","] objectAtIndex:1] floatValue]);

    [array removeObjectAtIndex:0];

    GMSMarkerOptions *options = [[GMSMarkerOptions alloc] init];
    options.position = pointsToUse[i];
    [mapView_ animateToLocation:pointsToUse[i]];
    [mapView_ addMarkerWithOptions:options];
}

我已经尝试了足够多的方法来搜索它,但没有足够的文档来回答我的问题.

I have tried enough to search for it but there isn't enough documentation to answer my question.

在此先感谢您的帮助.

推荐答案

这对我有用:

for(GMSMarker*marker in array)
    {
        GMSMarker *mkr= [[GMSMarker alloc]init];
        [mkr setPosition:CLLocationCoordinate2DMake(<coord>)];

        [mkr setAnimated:YES];
        [mkr setTitle:<Title>];
        [mkr setSnippet:<Snippet>];
        [mkr setMap:mapView_];
    }

使用最新的 Google Maps SDK.

Using latest Google Maps SDK.

希望能帮到你

这篇关于在 ios 中的谷歌地图上添加多个图钉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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