ios - 如何使用 google Api 查找我周围的地方
<p><p>我正在开发使用 Google API 的应用程序。我试图通过它找到我周围的地方。我正在使用下面的代码来获取数据,</p>
<pre><code>-(void)fetchedData:(NSData *)responseData {
//this is to parse out the json data
NSError *error = nil; //create some error handling here
NSDictionary *json = ;
//I'm told the returned results from Google will be an array obtained from the NSDictionary object with the key "results"
NSArray *places = ;
//display the data to the console for review
NSLog(@" Google data:\n%@", places);
}
</code></pre>
<p>但它显示 json status = Request Denied。
任何帮助将不胜感激。 </p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>维沙尔,</p>
<p>您可以使用以下代码块来完成:</p>
<pre><code> - (void) queryGooglePlaces: (NSString *) googleType
{
NSString *url = integerForKey:@"selectedDistance"]], googleType, kGOOGLE_API_KEY, appDelegate.selectedLanguageCode];
//Formulate the string as URL object.
NSURL *googleRequestURL=;
// Retrieve the results of the URL.
dispatch_async(kBgQueue, ^{
NSData* data = ;
if(data == nil)
{
;
;
}
else
{
;
}
});
}
- (void) queryGooglePlaces_WithNextPage
{
// Build the url string we are going to sent to Google. NOTE: The kGOOGLE_API_KEY is a constant which should contain your own API key that you can obtain from Google. See this link for more info:
NSString *url = integerForKey:@"selectedDistance"]], kGOOGLE_API_KEY];
//Formulate the string as URL object.
NSURL *googleRequestURL=;
// Retrieve the results of the URL.
dispatch_async(kBgQueue, ^{
NSData* data = ;
if(data == nil)
{
;
;
}
else
{
;
}
});
}
- (void)fetchedData:(NSData *)responseData
{
//parse out the json data
NSError* error;
NSDictionary *json = [NSJSONSerialization
JSONObjectWithData:responseData
options:kNilOptions
error:&error];
//The results from Google will be an array obtained from the NSDictionary object with the key "results".
if(isNextPageAvailable == FALSE)
;
NSArray *placesTemp = ;
if( != nil)
{
nextPageToken = ;
isNextPageAvailable = TRUE;
}
else
{
nextPageToken = @"";
isNextPageAvailable = FALSE;
}
for(int i=0;i<;i++)
{
NSMutableDictionary *placeDictionary = [ initWithDictionary:];
double lat1 = appDelegate.currentLatitude;
double long1 = appDelegate.currentLongitude;
double lat2 = [[[ objectForKey:@"location"] valueForKey:@"lat"] doubleValue];
double long2 = [[[ objectForKey:@"location"] valueForKey:@"lng"] doubleValue];
CLLocation *location1 = [ initWithLatitude:lat1 longitude:long1];
CLLocation *location2 = [ initWithLatitude:lat2 longitude:long2];
] forKey:@"distance"];
;
}
NSSortDescriptor *sortDescriptor;
sortDescriptor = [ initWithKey:@"distance" ascending:YES comparator:^NSComparisonResult(id obj1, id obj2) {
if ( < )
return NSOrderedAscending;
else
return NSOrderedDescending;
}];
NSArray *sortedArray = ];
;
;
;
;
;
// ;
//Plot the data in the places array onto the map with the plotPostions method.
// ;
}
- (void) queryGooglePlaceDetail
{
NSString *url = valueForKey:@"reference"], kGOOGLE_API_KEY, appDelegate.selectedLanguageCode];
//Formulate the string as URL object.
NSURL *googleRequestURL=;
// Retrieve the results of the URL.
dispatch_async(kBgQueue, ^{
NSData* data = ;
if(data == nil)
{
;
}
else
{
;
}
});
}
- (void)fetchedDetailPlaceData:(NSData *)responseData
{
//parse out the json data
NSError* error;
NSDictionary *json = [NSJSONSerialization
JSONObjectWithData:responseData
options:kNilOptions
error:&error];
NSDictionary *detailTempDic = [ initWithDictionary:];
valueForKey:@"distance"] forKey:@"distance"];
;
;
}
</code></pre>
<p>在这里,您必须传递来自 Google 地方信息的不同类型的对象,例如自动取款机、机场、餐厅、银行、医院、学校。</p>
<pre><code> ];
</code></pre>
<p>谢谢,
此致,
古普里特</p></p>
<p style="font-size: 20px;">关于ios - 如何使用 google Api 查找我周围的地方,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/25807163/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/25807163/
</a>
</p>
页:
[1]