-7
A
回答
0
你可以嘗試在網上迅速向目標C轉換器。像 http://objc2swift.me 這些轉換器用於將目標c轉換爲Swift。我知道你想把Swift轉換成客觀的C,但我認爲你可以在這裏學到一些想法。只需編寫代碼。 Swift非常類似於客觀的c。語法上的差異。你可以很容易理解。 *堆棧溢出不能寫入代碼。如果您有任何代碼問題。我們會幫助你。
0
這裏是代碼,創建一個按鈕,添加選擇器到該按鈕。希望你會設置你的谷歌地圖。
NSMutableData *webData;
@property NSURLConnection *connection;
-(void) getResult //call this in button selector
{
marker=nil; //create a GMSMarker globally.
[self.mapView clear];
NSString *strUrl = [NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/place/search/json?location=%f,%f&radius=%@&type=atm&sensor=true&name=%@&key=%@",latitude,longitude,_radius.text,_searchTxt.text,googleAPI_Key ];
[self addMarkerDataUrl:strUrl];
}
-(void)addMarkerDataUrl:(NSString *)urlString
{
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
NSString* urlTextEscaped = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlTextEscaped]
cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:10];
[request setHTTPMethod: @"GET"];
self.connection = [NSURLConnection connectionWithRequest:request delegate:self];
if(self.connection)
{
webData = [[NSMutableData alloc]init];
}
}
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
[webData setLength:0];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[webData appendData:data];
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
if (webData)
{
[self gettingData:webData ];
}
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
webData=nil;
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
NSLog(@" response %d",kCFURLErrorNotConnectedToInternet);
if ([error code] == kCFURLErrorNotConnectedToInternet)
{
NSDictionary *userInfo = [NSDictionary dictionaryWithObject:@"No Connection Error"
forKey:NSLocalizedDescriptionKey];
NSError *noConnectionError = [NSError errorWithDomain:NSCocoaErrorDomain code:kCFURLErrorNotConnectedToInternet userInfo:userInfo];
NSLog(@"error %@",noConnectionError);
[self handleError:noConnectionError];
}
else
{
[self handleError:error];
}
self.connection = nil;
[self errorInConnection];
}
- (void)handleError:(NSError *)error
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"SUBCOMMUNE" message:@"Timed Out" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
}
-(void)errorInConnection
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"ERROR" message:@"Try again after some time" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
}
- (void) gettingData:(NSData *)data
{
NSError* error;
NSDictionary* json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
NSArray* places = [json objectForKey:@"results"];
NSLog(@"Google Data: %@", places);
tempArray = [[NSMutableArray alloc]init];
NSDictionary *allDataDictionary = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
if([[NSString stringWithFormat:@"%@",[allDataDictionary objectForKey:@"status"]]isEqualToString:@"OK"])
{
collectionArray =[[NSMutableArray alloc]init];
locArray = [[NSMutableArray alloc]init];
NSMutableArray *legsArray = [[NSMutableArray alloc] initWithArray:allDataDictionary[@"results"]];
for (int i=0; i< [legsArray count]; i++)
{
[collectionArray addObject:[NSDictionary dictionaryWithObjectsAndKeys:legsArray[i][@"icon"],@"icon", legsArray[i][@"name"],@"name",legsArray [i][@"vicinity"],@"vicinity",legsArray[i][@"id"],@"id",nil]];
[locArray addObject:legsArray[i][@"geometry"][@"location"]];
[tempArray addObject:legsArray[i][@"vicinity"]];
}
NSLog(@"CollectionArray =%@",collectionArray);
NSLog(@"LocationArray =%lu",(unsigned long)locArray.count);
[self addMarkers];
}
else
{
NSString *msg=[allDataDictionary objectForKey:@"error_message"];
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Error !\n Check Radius or ATM Name" message:msg delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
}
}
-(void)addMarkers
{
for(int i=0;i<locArray.count;i++)
{
starting = [NSMutableDictionary dictionaryWithObjectsAndKeys:locArray[i][@"lat"],@"lat",locArray[i][@"lng"],@"lng", nil];
name = [NSMutableDictionary dictionaryWithObjectsAndKeys:collectionArray[i][@"name"],@"name",nil];
CLLocationCoordinate2D position = CLLocationCoordinate2DMake([[starting objectForKey:@"lat"] doubleValue] , [[starting objectForKey:@"lng"] doubleValue]);
marker1 = [GMSMarker markerWithPosition:position];
GMSCameraUpdate *updatedCamera=[GMSCameraUpdate setTarget:CLLocationCoordinate2DMake(latitude, longitude) zoom:15];
[self.mapView animateWithCameraUpdate:updatedCamera];
marker1.title = [name objectForKey:@"name"];
[marker1 setIcon:[UIImage imageNamed:@"Map Pin-48.png"]];
marker1.appearAnimation = YES;
marker1.map = self.mapView;
}
}
相關問題
- 1. 你可以幫我這個代碼
- 2. 你可以改進這個C#正則表達式代碼嗎?
- 3. 有人可以幫我翻譯這個C++代碼到C嗎?
- 4. 有人可以解釋這個JavaScript代碼給我嗎?
- 5. 任何人都可以解釋這個matlab代碼給我嗎?
- 6. 有人可以向我解釋這個C++代碼嗎?
- 7. 認爲你可以讓這個代碼更漂亮嗎?
- 8. 你能幫我理解這個C++模板代碼嗎?
- 9. 我可以縮短這段代碼嗎?
- 10. 這個jQuery代碼可以重構嗎
- 11. 這個小代碼可以優化嗎?
- 12. 這個cron代碼可以工作嗎?
- 13. 這個fopen代碼可以改進嗎
- 14. Haskell:這個代碼可以優化嗎?
- 15. 這個代碼塊可以縮短嗎?
- 16. 這個Go代碼可以重構嗎?
- 17. 這個Clojure代碼可以優化嗎?
- 18. 這個PHP代碼可以改進嗎?
- 19. 這個cython代碼可以優化嗎?
- 20. 我可以擺脫這個可怕的封鎖代碼嗎?
- 21. 你能簡化這個代碼嗎?
- 22. 你可以在UWP中的C#代碼中使用C++ DLL嗎?
- 23. 有人可以向我解釋這行c#代碼嗎?
- 24. C# - 我可以/應該簡化/改變這段代碼嗎?
- 25. 你可以在SSIS中重新使用代碼嗎?你能以編程方式更改源/目標嗎?
- 26. 你好,任何人都可以給我看RMI遠程回呼的例子(代碼)嗎?他們是這個過程的標準代碼嗎?
- 27. 你可以簡化這個查詢嗎?
- 28. 可以用c#中的內聯代碼輸出這個值嗎?
- 29. 這個C代碼可以創建殭屍進程嗎?
- 30. 有人可以解釋這個C++代碼嗎?
我嘗試,但我不知道迅速。 – Bharath
我是新的開發人員,我不知道swift.is有錯 – Bharath
你可以顯示你的嘗試代碼 –