Domanda

È conveniente da usare "- ReversteGeocODelocation: CompletionHandler:" Metodo per invertire il geocoding di una posizione.Ma come ottenere tutte le posizioni in una regione.

PS.Se ci sono diversi posti in una regione.Come potrei usare le informazioni della regione per scoprire tutti i posti?Come il geocoding inverso una posizione, data una coordinata, restituire una posizione.Qui voglio dare una regione, restituire tutte le località della regione.

È stato utile?

Soluzione

C'è un'API di Geocoder Google che restituisce JSON, è solo una specie di servizio Web che utilizza il metodo GET

e è l'API di Google Gecoder e Questo è il link per quel servizio Web e in questo link ho dato il nome della regionecome Londra.

Nota: è necessario includere la libreria Sbjson sul tuo codice.

Alla fine di quel link ho l'indirizzo aggiunto, se si aggiunge l'indirizzo, è necessario dare il nome della regione (o) se si aggiunge la latitudine e longitudine, è necessario dare coordinate e restituire i risultati di conseguenza. .

E il codice per chiamare Google API sarà come questo

                //Call the Google API
                NSString *req = [NSString stringWithFormat:@"http://maps.google.com/maps/api/geocode/json?sensor=false&address=%@", esc_addr];
                NSLog(@"The get address is %@", req);
                //Pass the string to the NSURL
                NSString *result = [NSString stringWithContentsOfURL:[NSURL URLWithString:req] encoding:NSUTF8StringEncoding error:NULL];
                NSLog(@"The result is %@", result);
                //Initialize the SBJSON Class
                SBJSON *parser = [[SBJSON alloc] init];
                NSError *error = nil;
                //Get the resullts and stored in the address array
                addressArray = [parser objectWithString:result error:&error];
                //Get the latitude values for the given address
                NSDictionary *dict = [[[addressArray valueForKey:@"results"] valueForKey:@"geometry"] valueForKey:@"location"];
                self.latitudeValue = [[dict valueForKey:@"lat"] objectAtIndex:0];
                self.longitudeValue = [[dict valueForKey:@"lng"] objectAtIndex:0];
                NSLog(@"LAT : %@",self.latitudeValue);
                NSLog(@"LONG : %@",self.longitudeValue);
.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top