当前位置: 首页 > 工具软件 > Foursquare > 使用案例 >

How to get Venue Coordinate of Foursquare

吕志诚
2023-12-01

Foursquare give us api to get this information

But the raw data is not perfect json object when I use Java to do this work.

I apply python to do this work. The code is more simple and perfect. 

The code is fellow:

import urllib2
import json
import pymongo
import sys, os, stat
from pymongo import Connection

c = Connection('localhost', 27017)

db = c.FourS2
finf = db.FourInformation
fpho = db.FourPhotos
ftip = db.FourTips
VenueList = db.Venuelist

for item in VenueList.find():
    
    venueid = item['_id']
    url1 = 'https://api.foursquare.com/v2/venues/'
    url2 = '?client_id=HD0ZXRNBOA4XPJWZOKU1IQMN12AJAKWNFELCD10FSLYGHYMT&client_secret=DQLZUI0M0SXTQTPR4DMMZYTZHE45GISJBNOR4MMWO3V4R41L'
    request = url1+venueid+url2
    content = urllib2.urlopen(request).read()

    temp = json.loads(content)
    
    lat = temp['response']['venue']['location']['lat']
    lng = temp['response']['venue']['location']['lng']
    item['lat'] = lat
    item['lng'] = lng
    
    VenueList.save(item)


Here, venueid is the venue id in Foursquare.

we apply package json to convert the raw data into json object. 

Finally, we save this data into Mongodb.

 类似资料:

相关阅读

相关文章

相关问答