2014-01-07 41 views
0

我想繪製Google Maps for iOS上的標記,並通過包含包含經度和緯度的JSON文件來繪製標記。我可以在代碼中手動執行,通過替換值。 問題是我不知道如何在JSON文件的地圖上顯示新標記。Google地圖上的繪圖標記JSON文件中的iOS

這裏是我的代碼:

- (void)addDefaultMarkers { 
// Add a custom 'glow' marker around Sydney. 
GMSMarker *sydneyMarker = [[GMSMarker alloc] init]; 
sydneyMarker.title = @"Sydney!"; 
sydneyMarker.icon = [UIImage imageNamed:@"glow-marker"]; 
sydneyMarker.position = CLLocationCoordinate2DMake(25.062718, 55.130761); 
sydneyMarker.map = mapView_; 
GMSMarker *melbourneMarker = [[GMSMarker alloc] init]; 
melbourneMarker.title = @"Melbourne!"; 
melbourneMarker.icon = [UIImage imageNamed:@"arrow"]; 
melbourneMarker.position = CLLocationCoordinate2DMake(25.100822, 55.17467); 
melbourneMarker.map = mapView_; 
} 

關於如何做到這一點任何想法?

+0

再檢查一下我在這個環節上的問題,http://stackoverflow.com/questions/20902732/how-to-plot-the-markers-in-google-maps-from-a-dictionay-在-IOS。這個鏈接將有助於你獲得 – chandru

+0

嗎? @Al_fareS – chandru

+0

我閱讀了你的文章,而且在我看來,我想對你做同樣的想法,你能告訴我如何解析JSON數據並將其作爲字典收集嗎? 代碼片段將非常有幫助。 –

回答

0

chech我的問題在這個鏈接,stackoverflow.com/questions/20902732/...。這個鏈接將有所幫助, 首先解析json數據。並收集它作爲陣列或字典,則U可以直接在地圖
繪製的值的前兩行是將數據解析成一個數組

SBJsonParser *jsonParser = [SBJsonParser new];  
NSArray *jsonData = (NSArray *) [jsonParser objectWithString:outputData error:nil]; 

然後,環路應該繼續,直到沒有。值,

for(int i=0;i<[jsonData count];i++) 
{ 
NSDictionary *dict=(NSDictionary *)[jsonData objectAtIndex:i]; 
Nslog(@"%@",dict); 
double la=[[dict objectForKey:@"latitude"] doubleValue]; 
double lo=[[dict objectForKey:@"longitude"] doubleValue]; 

CLLocation * loca=[[CLLocation alloc]initWithLatitude:la longitude:lo]; 
CLLocationCoordinate2D coordi=loca.coordinate; 

marker=[GMSMarker markerWithPosition:coordi]; 
marker.snippet = @"Hello World"; 
marker.animated = YES; 
marker.map = mapView; 
} 
+0

你明確得到了答案嗎?還有什麼疑問? – chandru

+0

對我來說這似乎很好,我唯一懷疑的地方就是在哪裏添加JSON文件鏈接?所以我保持經緯度值不斷變化。 –

+0

因爲你必須研究關於網絡服務,請檢查此鏈接http://codewithchris.com/tutorial-how-use-use-ios-nsurlconnection-by-example/ – chandru