Search code examples
pythongoogle-mapsgps

Extract latitude and longitude from coordinates


I have this sort of data, and I want to extract the latitude and longitude in Python.

col[index]=
52.420223333,-1.904525
52.420221667,-1.904531667
52.420221667,-1.904536667
52.42022,-1.904545
52.420218333,-1.904553333
52.420216667,-1.904556667

I know how to do this in PHP, but wasn't sure how to implement it in Python:

sscanf($string, '"(%f, %f)"', $lat, $lng);

EDIT: This code runs and outputs the coordinates above

for index in range(len(col)):
    print col[index]

In the for loop, is it possible to get the lat and long data. e.g. for the first iteration, lat=52.420223333 and lon=-1.904525.


Solution

  • for index in range(len(col)):
        lat, lon = col[index].split(",")
        print "lat=%s, lon=%s" % (lat, lon)