0

My addMarker function wasn't adding markers, so I looked for where it was called and put an alert in the block to see if it got there. It didn't, because the size of data (the return of the flask url /update) was zero. I pasted this

/update?ne=35.135291997229366%2C-106.49573671874998&sw=35.03527734456558%2C-106.7154632812499

into the browser bar after my username, and did indeed receive an empty object back. I pasted the same into the staff solution and got the expected output. I re-downloaded the original resources to ensure that I hadn't accidentally changed the definition of /update and I'm almost positive I didn't.

Here is what I have there

@app.route("/update")
def update():
"""Find up to 10 places within view."""

# ensure parameters are present
if not request.args.get("sw"):
    raise RuntimeError("missing sw")
if not request.args.get("ne"):
    raise RuntimeError("missing ne")

# ensure parameters are in lat,lng format
if not re.search("^-?\d+(?:\.\d+)?,-?\d+(?:\.\d+)?$", request.args.get("sw")):
    raise RuntimeError("invalid sw")
if not re.search("^-?\d+(?:\.\d+)?,-?\d+(?:\.\d+)?$", request.args.get("ne")):
    raise RuntimeError("invalid ne")

# explode southwest corner into two variables
(sw_lat, sw_lng) = [float(s) for s in request.args.get("sw").split(",")]

# explode northeast corner into two variables
(ne_lat, ne_lng) = [float(s) for s in request.args.get("ne").split(",")]

# find 10 cities within view, pseudorandomly chosen if more within view
if (sw_lng <= ne_lng):

    # doesn't cross the antimeridian
    rows = db.execute("""SELECT * FROM places
        WHERE :sw_lat <= latitude AND latitude <= :ne_lat AND (:sw_lng <= longitude AND longitude <= :ne_lng)
        GROUP BY country_code, place_name, admin_code1
        ORDER BY RANDOM()
        LIMIT 10""",
        sw_lat=sw_lat, ne_lat=ne_lat, sw_lng=sw_lng, ne_lng=ne_lng)

else:

    # crosses the antimeridian
    rows = db.execute("""SELECT * FROM places
        WHERE :sw_lat <= latitude AND latitude <= :ne_lat AND (:sw_lng <= longitude OR longitude <= :ne_lng)
        GROUP BY country_code, place_name, admin_code1
        ORDER BY RANDOM()
        LIMIT 10""",
        sw_lat=sw_lat, ne_lat=ne_lat, sw_lng=sw_lng, ne_lng=ne_lng)

# output places as JSON
return jsonify(rows)

What am I missing?

Update: the sql query isn't returning anything. I THINK my sql table must be malformed. This is what I got when I ran .schema places in sqlite3

CREATE TABLE places (country_code char(2), postal_code varchar(20), place_name varchar(180), admin_name1 varchar(100), admin_code1 varchar(20), admin_name2 varchar(100), admin_code2 varchar(20), admin_name3 varchar(100), admin_code3 varchar(20), latitude varchar(100), longitude varchar(100), accuracy char(1));
1

I was having a similar issue, and I think the problem is with your latitude and longitude. Try changing them to numeric types using phpliteadmin.

When they're a varchar/text type, then the math in the SQL queries doesn't work.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .