2014-11-22 3 views
0

iOS에서 GoogleMaps로 작업하고 있습니다. {동적으로 텍스트를 기반으로지도 위치 가져 오기

//code5.1 
//Donepudi my hometown 
GMSCameraPosition * cameraPosition = [GMSCameraPosition cameraWithLatitude: 
             16.149319 longitude:80.817017 zoom:6]; 
//itouchmap.com for accessig Latitude and longitude 

//code5.2 
//for set camera postion 
mapView = [GMSMapView mapWithFrame:CGRectZero camera:cameraPosition]; 

//code5.3 
//for privacy reasons our location is deisabled. 
mapView.myLocationEnabled = NO;//default no. 

//code5.4 
//set self view as a map view 
self.view = mapView; 

//code5.5 
/** 
* A marker is an icon placed at a particular point on the map's surface. A 
* marker's icon is drawn oriented against the device's screen rather than the 
* map's surface; i.e., it will not necessarily change orientation due to map 
* rotations, tilting, or zooming. 
*/ 
GMSMarker *marker = [[GMSMarker alloc]init]; 

//PINPOINT LOCATION IS SET TO OUR REQUIREMENT. 
marker.position = CLLocationCoordinate2DMake(16.149319, 80.817017); 

//SET TITLE SHOWS TOP OF THE PIN POINT 
marker.title = @"Donepudi"; 

//SET SNNIPET 
marker.snippet = @"Donepudi,INIDIA"; 

//SET OVERLAY VIEW 
marker.map = mapView; 

}

(무효) pointingLocation 하지만 (주소) 텍스트를 설정할 -

나는 성공적으로 정적이 코드를

를 사용하여 주어진 위치를 가리키는입니다 동적으로 지도보기에서 위치를 가리키는 텍스트 (주소)를 기반으로

답변

0

나는 ethod

- (CLLocationCoordinate2D) geoCodeUsingAddress:(NSString *)address 
{ 

    double latitude = 0, longitude = 0; 

    NSString *esc_addr = [address 
          stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 

    NSString *req = [NSString 

     stringWithFormat:@"http://maps.google.com/maps/api/geocode/json    
            sensor=false&address=%@", esc_addr]; 

    NSString *result = [NSString stringWithContentsOfURL:[NSURL URLWithString:req] 
             encoding:NSUTF8StringEncoding error:NULL]; 
    if (result) { 

     NSScanner *scanner = [NSScanner scannerWithString:result]; 

     if ([scanner scanUpToString:@"\"lat\" :" intoString:nil] && 
      [scanner scanString:@"\"lat\" :" intoString:nil]) { 

        [scanner scanDouble:&latitude]; 

        if ([scanner scanUpToString:@"\"lng\" :" intoString:nil] && 
         [scanner scanString:@"\"lng\" :" intoString:nil]) { 

           [scanner scanDouble:&longitude]; 
        } 
     } 
    } 
    CLLocationCoordinate2D center; 
    center.latitude = latitude; 
    center.longitude = longitude; 

    return center; 
} 

출력 :

때 나는 자동 GoogleMap으로에서 필요한 위치를 가리키는 문자열을 통과 이제까지.