0

我想做以下事情 - 允许用户在 ios 应用程序中输入物理地址。- 此地址转换为经度/纬度 - Django 服务器代码检查以查看附近的位置。

我怎样才能最有效地做到这一点?

我应该在ios应用程序中将地址转换为经度和纬度,然后将坐标发送到django服务器代码,还是应该将地址发送到django服务器代码,然后将地址转换为经度和纬度?

任何帮助,将不胜感激!

4

3 回答 3

5

According to the Apple's Location Awareness Programming Guide You can achieve this using a CLGeocoder object:

CLGeocoder* geocoder = [[CLGeocoder alloc] init];
[geocoder geocodeAddressString:@"Your Address"
     completionHandler:^(NSArray* placemarks, NSError* error){
         for (CLPlacemark* aPlacemark in placemarks)
         {
         // Process the placemark.
         }
}];

A CLPlacemark object has a property called location that yields latitude and longitude for the place.

于 2013-05-22T14:37:33.423 回答
1

(latitude, longitude)您可以使用此函数在 django 端获取元组

import urllib, urllib2
import simplejson as json

def getLatLng( address ):
    """ Native address format is House Number, Street Direction, Street Name, 
    Street Suffix, City, State, Zip, Country """

    TIMEOUT = 3

    try:
        url = "http://maps.google.com/maps/api/geocode/json?address=" + urllib.quote_plus( address.encode('utf-8') ) + "&sensor=false"
        opener = urllib2.build_opener()
        req = urllib2.Request( url )

        data = json.load( opener.open(req, None, TIMEOUT) )
        results = data['results']
        if len( results ):
            location = results[0]['geometry']['location']
            return  ( location['lat'], location['lng'] )
        else:
            return None
    except:
        return None
于 2013-05-23T07:38:43.667 回答
0

Use the below link,this will return json which consist of latitude and longitude for the physical address.

http://maps.google.com/maps/api/geocode/json?address=Newyork&sensor=false

于 2013-05-22T14:37:30.700 回答