How to convert nsstring value of text in CLLocationCoordinate2D to objective-c for google map

I want to give the user the opportunity to indicate the name of the location that he wants to find on the google map from iphone. when the user has placed the name of the location on which a particular map should be displayed.

Now I do this, fixing the value of the coordinate in my latitude and longitude of the object.

CLLocationCoordinate2D location=mapView.userLocation.coordinate;

location.latitude=19.14;
location.longitude=73.10;

Is there any way to give the value of this coordinate in the text and convert this value to the value of CLLocationCoordinate2D?

+3
source share
2 answers

I do not quite understand your question, but if you want to convert NSString to CLLocationCoordinate2D, you can use the following:

{
    [self useLocationString:@"19.14,73.10"];
}

- (void) useLocationString:(NSString*)loc
{
    // the location object that we want to initialize based on the string
    CLLocationCoordinate2D location;

    // split the string by comma
    NSArray * locationArray = [loc componentsSeparatedByString: @","];        

    // set our latitude and longitude based on the two chunks in the string
    location.latitude = [[[NSNumber alloc] initWithDouble:[[locationArray objectAtIndex:0] doubleValue]] autorelease];
    location.longitude = [[[NSNumber alloc] initWithDouble:[[locationArray objectAtIndex:1] doubleValue]] autorelease];

   // do something with the location
}

, , NSArray SeparatedByString.

+3

.

- (CLLocationCoordinate2D) get2DCoordFromString:(NSString*)coordString
{
    CLLocationCoordinate2D location;
    NSArray *coordArray = [coordString componentsSeparatedByString: @","];
    location.latitude = ((NSNumber *)coordArray[0]).doubleValue;
    location.longitude = ((NSNumber *)coordArray[1]).doubleValue;

    return location;
}
0

Source: https://habr.com/ru/post/1729884/


All Articles