0

I use a location api to set my lat and long into variables. Which I am tying to pass into my location for my google API call.

I have tried different sequences of turning two string variables into one. (str(lat), str(lon)), (str(lat) + str(lon)), str(lat), str(lon), str(lat) + str(lon), and (str(lat, lon))

check_url = 'http://api.ipstack.com/check?access_key=3fea3b33a38ef7abd674c9e0515183be'
r = requests.get(check_url)
j = json.loads(r.text)
lat = j['latitude']
lon = j['longitude']
mylocation = (str(lat), str(lon))

I am trying to pass the lat and lon into the variable

LOCATION = 'mylocation'

for my api call.

It prints as '38.9208','-77.036'

But for my api call I need it to return as '38.9208,-77.036'

1 Answers1

0

You could use str.join to concatenate lat and lon:

import requests
import json

check_url = 'http://api.ipstack.com/check?access_key=3fea3b33a38ef7abd674c9e0515183be'
r = requests.get(check_url)
j = json.loads(r.text)
lat = j['latitude']
lon = j['longitude']

mylocation = (str(lat), str(lon))

print(','.join(mylocation))

Prints:

39.3752,21.8903
Andrej Kesely
  • 168,389
  • 15
  • 48
  • 91