How can I get the name of the current city?

I want to get the current iPhoneOS user. How can i do this?

+2


source to share


3 answers


You are searching for IP addresses. This usually includes a database such as "MaxMind" .



Well, I have an iPod Touch, so I forgot that the iPhone might not have an IP card at that moment in the city (my home ip is static so that helps too) You can also read the Core Location Docs . As far as I can see, the class CLLocation

only binds in latitude, longitude, altitude, heading, and speed. You will need to have your own RTree for the approximate city boundaries in order to be able to make a definition or use a web service call, perhaps Google Maps or GeoNames FindNearbyPlaceName

web service ( St. Gallen Example ).

+2


source


Take a look:



IPhone SDK 3.0 and iPhone Dev SDK
0


source


see CLLocationManager class

- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
       fromLocation:(CLLocation *)oldLocation
 {





       if (newLocation) {
               longitudeLabel.text=[NSString stringWithFormat:@"%f",newLocation.coordinate.longitude ];
               latitudeLabel.text=[NSString stringWithFormat:@"%f",newLocation.coordinate.latitude ];
                        }




      CLGeocoder * geoCoder = [[CLGeocoder alloc] init];

      [geoCoder reverseGeocodeLocation: locationManager.location completionHandler: 

 ^(NSArray *placemarks, NSError *error) {




                placemark = [placemarks objectAtIndex:0];


               //the below code gives the city name

                NSString *city=placemark.locality; 


                NSLog(@"I am currently at %@",city);


              //String to hold address

              NSString *locatedAt = [[placemark.addressDictionary valueForKey:@"FormattedAddressLines"] componentsJoinedByString:@", "];
              NSLog(@"I am currently at %@",locatedAt);
              NSMutableArray *FullAddress=[placemark.addressDictionary valueForKey:@"FormattedAddressLines"];



                  //gives the state 

              NSString * state=[placemark administrativeArea];

              country=[placemark.addressDictionary valueForKey:@"Country"];
              CountryCode=[placemark.addressDictionary valueForKey:@"CountryCode"];
              Name=[placemark.addressDictionary valueForKey:@"Name"];
              State1=[placemark.addressDictionary valueForKey:@"State"];
              Street=[placemark.addressDictionary valueForKey:@"Street"];


 }];



}

      

see the delegate class for CLPlacemark, it provides a set of information about the current location.

0


source







All Articles