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

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.

sumachaa’s picture

To have the distance filter; please make sure to have the geocoder module; https://www.drupal.org/project/geocoder
To view the distance value; In the settings for the LatLong pair field check the box Show distance instead of coordinates.