승환 0 Newbie Poster

I want to know addresses of some coordinates, so I use geopy-1.10.

my code is

from geopy.geocoders import Nominatim

def to_degrees(lats, longs):
    lat_deg = lats[0:2]
    lat_mins = lats[2:4]
    lat_secs = int(lats[5:])*60/10000
    lat_msecs = int(lats[5:])*60%10000
    lat_str = lat_deg + u'.'+ lat_mins + str(lat_secs) + str(lat_msecs) 

    lon_deg = longs[0:3]
    lon_mins = longs[3:5]
    lon_secs = int(longs[6:])*60/10000
    lon_msecs = int(longs[6:])*60%10000
    lon_str = lon_deg + u'.'+ lon_mins + str(lon_secs) + str(lon_msecs)
    return [lat_str, lon_str]

def gpgga():
    data = ser.readline()
    if data[0:6] == "$GPGGA":
        gpgga = nmea.GPGGA()
        gpgga.parse(data)
        lats = gpgga.latitude
        lat_dir = gpgga.lat_direction
        longs = gpgga.longitude
        long_dir = gpgga.lon_direction

        lat_lon = to_degrees(lats, longs)

        p = lat_lon[0] + "," + lat_lon[1]
        geolocator = Nominatim()
        location = geolocator.reverse(p, timeout = None)
        print "p:", p
        print(location.address)

my output is

Latitude:  37.27265020"N & Longitude:  126.56552840"E

but address appears

301, 대부북동 (Daebubukdong), 안산시 (Ansan), 경기(kyungki), 대한민국(S.Korea)

where Latitude: 37.244358, Longitude: 126.583535

How can I fix this problem?? I tried to add and subtract errors but I failed because of different types; unicode(lat_lon) vs float...

as I know, changing unicode to float or float to unicode is impossible.

help me, please..

I changed type to str, float and calculate(latitude - 0.02803, longitude+0.017907) and change type again to unicode.

but result is

301, 대부북동 (Daebubukdong), 안산시 (Ansan), 경기, 대한민국
location.latitude, location.longitude : 37.2915257, 126.578164
Latitude:  37.27256"N & Longitude:  126.565540"E

how can i solve this problem?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.