Hamoudy
Hamoudy

Reputation: 579

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.

Upvotes: 0

Views: 1698

Answers (1)

Holy Mackerel
Holy Mackerel

Reputation: 3279

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

Upvotes: 3

Related Questions