gpt4 book ai didi

javascript - 如何在 iOS 应用程序中使用 GoogleMap JavaScript API?

转载 作者:行者123 更新时间:2023-11-29 00:55:05 26 4
gpt4 key购买 nike

Google 提供 an iOS SDK然而,对于 GoogleMap,GoogleMap JavaScript API提供更多功能,包括 custom stylingdata visualisation ,这是我想在我的应用中实现的功能。

那么有什么方法可以在我的应用中使用这些 JavaScript API 吗?

我在考虑是否可以将 map 嵌入到 WebView 中,以便我可以在应用程序中执行 JavaScript 操作?这可能吗?性能危害如何?

提前致谢。

最佳答案

我正在使用 AFNetworking 框架。我做了它的子类。 CUK_Client 是子类的名称。

google api examples显示方法的类型(POST 或 GET)。

您可以根据自己的需要进行修改。

makeRequestGet 是一个通用的 GET 方法,您可以根据需要使用任何参数和路由调用它。例如,在 getDirection 方法中,我用它来获取两个坐标之间的方向。

.h文件

@interface CUK_Client : AFHTTPSessionManager
+ (CUK_Client *) sharedClient;
+ (CUK_Client *) googleMapsClient;

- (void)makeRequestGet:(NSString *) route withParamaters:(NSDictionary *)parameters completion:(DefaultIdResultBlock) completion ;

- (void)getDirection:(NSDictionary *)params completion:(DefaultIdResultBlock) completion;

- (void)beaconsVisited:(NSArray *)beacons completion:(DefaultIdResultBlock) completion;
@end

.m文件

@implementation CUK_Client

+ (CUK_Client *) googleMapsClient {
static CUK_Client *googleMapsClient = nil;
static dispatch_once_t onceToken;
dispatch_once (&onceToken , ^ {
googleMapsClient = [[self alloc] initWithBaseURL:[NSURL URLWithString:@"http://maps.googleapis.com/"]];

});

return googleMapsClient;
}


- (void) makeRequestGet:(NSString *) route withParamaters:(NSDictionary *)parameters completion:(DefaultIdResultBlock) completion {

[self GET:route
parameters:parameters
success:^(NSURLSessionDataTask *task, id responseObject) {

return completion ( nil ,responseObject );

} failure:^(NSURLSessionDataTask *task, NSError *error) {

return completion ( [error localizedDescription] , nil );
}];
}

-(void)getDirection:(NSDictionary *)params completion:(DefaultIdResultBlock)completion {

[self makeRequestGet:@"maps/api/directions/json" withParamaters:params completion:completion];
}

@end

关于javascript - 如何在 iOS 应用程序中使用 GoogleMap JavaScript API?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37672615/

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