【问题标题】:Retrieving map data from Google or Apple APIs / offline map options?从 Google 或 Apple API/离线地图选项中检索地图数据?
【发布时间】:2014-02-08 05:01:23
【问题描述】:

我正在下载 JSON 格式的地址信息并将注释引脚放置在 MKMapView 上。

数据不包含 GPS 坐标,并且数据服务的一些用户输入地名而不是街道地址。我目前正在尝试使用 Google 的 maps.googleapis.com 来检索 GPS 坐标;但是这很慢,我怀疑我很快就会超过谷歌对服务每日点击次数的限制。

我考虑将所有地图数据下载到服务器,将 GPS 坐标存储在该服务器上,然后让 iPhone 应用程序查询该服务器。我还可以使用地址创建一个 CoreData 数据库;但是这不会随着新地址添加到网络服务而更新。

是否有人对加快原始查询的其他方法或建议有建议?

如果有帮助,我可以发布代码。

谢谢!

【问题讨论】:

  • 这是非法的顺便说一句。如果没有谷歌地图,你不能使用谷歌的地理编码器(我上次检查过)
  • Google 有专门针对 iPhone 的 API,所以不要认为我违反了任何许可协议。
  • "(g) 没有 Google 地图,不得使用内容。..." - 例如在developers.google.com/maps/terms
  • 好吧,您可能是对的,尽管您引用的段落也有警告“除非您在 Maps API 文档中明确允许这样做”。但正如我在问题中推断的那样,我对其他选择持开放态度。
  • a) 不要将其缓存在服务器上,b) 使用 GMSMapiew 或 c) 使用苹果地理编码器

标签: ios google-maps-api-3 mkmapview


【解决方案1】:

向 Daij-Djan 致敬。他是对的。随着版本 5 的更改,没有 Google 地图就不能再使用 Google API。有很多教程展示了如何将 iPhone Map 与 Google API 结合使用,但想必这可能会在未来让您头疼。

CLGeocoder 运行良好,对用户而言实际上比 Google API 更快。这是我所做的:

- (void) getCoordinatesForTheseLocations:(NSArray*) meetRecords
{
NSInteger countOfAnnotations = [meetRecords count];

if (debug==1) NSLog(@"countOfAnnotations equals %ld", (long)countOfAnnotations);
NSInteger __block iCount = 0;
for (NSDictionary* meet in meetRecords) {

        NSString *location = [NSString stringWithFormat:@"%@, %@, %@",
                              [[meet objectForKey:MEET_VENUE] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]],
                              [[meet objectForKey:MEET_CITY] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]],
                              [[meet objectForKey:MEET_STATE_ABBREV] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]];

        CLGeocoder *geocoder = [[CLGeocoder alloc] init];
        [geocoder geocodeAddressString:location completionHandler:^(NSArray *placemarks, NSError *error) {
            CLLocationCoordinate2D coordinates;
            CLPlacemark* bestGuess;

            if (error)
            {…} else if (placemarks && placemarks.count > 0) {

               NSMutableDictionary* meetInfoForAnnotation = [[NSMutableDictionary alloc] init];

                if (debug==2) NSLog(@"meet = %@", meet);

                meetInfoForAnnotation = [meet mutableCopy];

                if (debug==2) NSLog(@"Received placemarks: %@", placemarks);


                bestGuess = [placemarks objectAtIndex:0];
                coordinates.latitude = bestGuess.location.coordinate.latitude;
                coordinates.longitude = bestGuess.location.coordinate.longitude;

                [meetInfoForAnnotation setObject:[NSNumber numberWithDouble:coordinates.longitude] forKey:MEET_LONGITUDE];
                [meetInfoForAnnotation setObject:[NSNumber numberWithDouble:coordinates.latitude] forKey:MEET_LATITUDE];

                [self mapAnnotations:meetInfoForAnnotation];

            }

            if (iCount == countOfAnnotations - 1) {  // Update MapView if have reached end of XML records.
                dispatch_async(dispatch_get_main_queue(), ^{

                    //            NSLog(@"%@",meetsWithCoordinates);
                    myPinColor = MKPinAnnotationColorPurple;

                    [self setAnnotations:self.meetAnnotations];
                });
            }
            if (debug==1) NSLog(@"iCount = %d and countOfAnnotations = %d",iCount, countOfAnnotations);
            iCount ++;
        }];
    }
}

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-03-26
    • 1970-01-01
    • 1970-01-01
    • 2017-03-25
    • 2012-03-09
    • 2015-01-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多