Last updated 25 August 2013. Created on 25 August 2013.
Edited by drunken monkey. Log in to edit this page.

These screenshots show shortly how to add an exposed filter for a Geofield to a Search API-powered view:

Required modules:

Search API Location, Search API Location Views

Fields to index (for Geofield "Location"):
Location » LatLong Pair

Exposed filter on "Location » LatLong Pair":
Expose, Expose operator, Geocoder input, Google Geocoder
Leave the rest on the defaults

Result in an example view:
Location filter is shown

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.

Comments

fdefeyter@gmail.com’s picture

Sorry but I don not get this field "distance" in the filter. Any idea why?

I am using geofield... Thanks!

De Feyter Frédéric - Thatsit.be

andsigno82’s picture

Experiencing the same lack of field.
i'm only able to set the label of filter operator if I expose it.

Barthy’s picture

Have you found a fix, workaround or anything comparable for this problem?

pinkonomy’s picture

Is this possible for the address to use the Google autocomplete form?
thanks

creathing’s picture

@pinkonomy, did you find a solution for your problem? I'm looking for something simular...

pinkonomy’s picture

Sorry I didn't find how to do this,if you found it please post here,thanks

danisha’s picture

I just need to have a field which calculates the distance between the entered zip code and its nearby location. Same as the google map directions.

I am unable to find out the same.

Can someone please help me in this?

Thanks
Danish

danisha’s picture

Hi Have used the below php code to find the distance between two points:-

function distance($lat1, $lon1, $lat2, $lon2, $unit) {
$theta = $lon1 - $lon2;
$dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
$dist = acos($dist);
$dist = rad2deg($dist);
$miles = $dist * 60 * 1.1515;
$unit = strtoupper($unit);
if ($unit == "K") {
return ($miles * 1.609344);
} else if ($unit == "N") {
return ($miles * 0.8684);
} else {
return $miles;
}
}

We just needs to pass the lat and long of both the points. Gives a pretty accurate results.

gaurav.pahuja’s picture

I am using geofield 7.x-2.3 but not getting this filter criterion in views.