Note that there are some explanatory texts on larger screens.

plurals
  1. POGeopy ValueError "Didn't find exactly one match" when geocoding
    text
    copied!<p>In Django, I have been trying to get a search field to geocode a location and spit out a list from my db sorted by distance. So far everything works except when I search for a location that Google returns multiple results form such as "ann arbor, MI". I get the ValueError "Didn't find exactly one placemark! (Found 2.)" Here is my views.py</p> <pre><code>from django.shortcuts import render_to_response from models import CampSite from geopy import geocoders from django.contrib.gis.geos import * from django.contrib.gis.measure import D from campsites.forms import SearchForm from django.http import HttpResponseRedirect def results(request): query = request.GET['q'] g = geocoders.Google(resource='maps') location, (lat, lon) = g.geocode(query) pnt = fromstr("POINT(%s %s)" % (lon, lat)) distance_from_point = {'mi':'2000'} results = CampSite.objects.filter(lonlat__distance_lte=(pnt,D(**distance_from_point))).distance(pnt).order_by('distance') return render_to_response('results.html',{'location': location, 'lat': lat, 'lon': lon, 'results':results}) </code></pre> <hr> <p>The common solution I found online was to change</p> <p><code>location, (lat, lon) = g.geocode(query)</code> </p> <hr> <p>to </p> <hr> <p><code>location, (lat, lon) = g.geocode(query, exactly_one=False)</code></p> <p>However, this produced the new ValueError "String or unicode input unrecognized as WKT EWKT, and HEXEWKB."</p> <p>This is my first django project I'm doing outside of tutorials, so thankyou for being gentile. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload