Question

I am to reverse Geo Code Latitude and Longitude of some location and want to get address of that location. I have done it through google web service but it takes time. I want to know if there is some other good and efficient approach.

Currently calling this service,

NSString * getAddress = [NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/geocode/json?latlng=%@,%@&sensor=true",Lattitude,Longitude];
Was it helpful?

Solution

You can use CLGeocoder:

[self.geocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error){
    CLPlacemark *placemark = placemarks[0];
    NSLog(@"Found %@", placemark.name);
}];

This will still take time though, since both methods use web services to convert lat / long into a place

OTHER TIPS

Try This code .

geoCoder = [[CLGeocoder alloc]init];
    [self.geoCoder reverseGeocodeLocation: locationManager.location completionHandler:

     //Getting Human readable Address from Lat long,,,

     ^(NSArray *placemarks, NSError *error) {
         //Get nearby address
         CLPlacemark *placemark = [placemarks objectAtIndex:0];
            //String to hold address
         NSString *locatedAt = [[placemark.addressDictionary valueForKey:@"FormattedAddressLines"] componentsJoinedByString:@", "];
            //Print the location to console
         NSLog(@"I am currently at %@",locatedAt);
     }];

Have a look at GLGeocoder. Specifically reverseGeocodeLocation:completionHandler:

You can use Apple's CLGeocoder (part of CoreLocation). Specifically, the – reverseGeocodeLocation:completionHandler: method which will return a dictionary of address data for the given coordinates.

Have a look at this tutorial, or, if just want something to copy quickly: NSArray *addressOutput; CLLocation *currentLocation; //assumes these instance variables

// Reverse Geocoding
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder reverseGeocodeLocation:currentLocation completionHandler:^(NSArray *placemarks, NSError *error) {
    NSLog(@"Found placemarks: %@, error: %@", placemarks, error);
    if (error == nil && [placemarks count] > 0) {
        NSMutableArray *tempArray = [[NSMutableArray alloc] initWithCapacity:[placemarks count]];
        for (CLPlacemark *placemark in placemarks) {
            [tempArray addObject:[NSString stringWithFormat:@"%@ %@\n%@ %@\n%@\n%@",
                                  placemark.subThoroughfare, placemark.thoroughfare,
                                  placemark.postalCode, placemark.locality,
                                  placemark.administrativeArea,
                                  placemark.country]];
        }
        addressOutput = [tempArray copy];
    }
    else {
        addressOutput = nil;
        NSLog(@"%@", error.debugDescription);
    }
}];

Based off the code in the tutorial.

If you to not want to use google API, try this code - basically transforms latitude and longitude inputs into ZIPs (can be adjusted to adresses).

pip install uszipcode

# Import packages
from uszipcode import SearchEngine
search = SearchEngine(simple_zipcode=True)
from uszipcode import Zipcode
import numpy as np

#define zipcode search function
def get_zipcode(lat, lon):
    result = search.by_coordinates(lat = lat, lng = lon, returns = 1)
    return result[0].zipcode

#load columns from dataframe
lat = df_shooting['Latitude']
lon = df_shooting['Longitude']

#define latitude/longitude for function
df = pd.DataFrame({'lat':lat, 'lon':lon})

#add new column with generated zip-code
df['zipcode'] = df.apply(lambda x: get_zipcode(x.lat,x.lon), axis=1)

#print result
print(df)

#(optional) save as csv
#df.to_csv(r'zip_codes.csv')
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top