Jump to content

"radius search" with FieldtypeMapMarker


Recommended Posts

Hey guys,

i am planning a "radius search" for branches (in Germany).

Within a form the user inserts his postal code and choose from one of the distance (20km, 50km, 100km) and gets all the branches in his radius.
The branches are saved as pages with the fieldtype MapMarker, where you have latitude and longitude.
http://modules.processwire.com/modules/fieldtype-map-marker/ )

did somebody did something similar in the past? I am just asking, before i will spend the whole weekend in front of the pc :-[

Link to comment
Share on other sites

  • 2 weeks later...
  • 2 weeks later...

It's been a while and i share my first results:

1) Make some pages with FieldtypeMapMarker
2) Build a form with an input for the Zipcode/PLZ and a select for the radius.
3)  upload the .tab file in your template (german zipcodes)

tomorrow i will make the styling and getting the distance between plz and results and render the google maps.



function plztolatlong($plz) {
	$fileData = @file_get_contents(OGDB_LOCAL_DATA_FILE);
	if ( $fileData == FALSE ) {
		die("ABBRUCH: konnte Daten nicht laden (".OGDB_LOCAL_DATA_FILE.")\n");

	$fileData = explode("\n",$fileData);

	for ( $i=1; $i < count($fileData); $i++ ) {
		$fileRow = explode("\t",$fileData[$i]);
		if ( $plz == $fileRow[1] ) {
			$origin_lon = $fileRow[2];
			$origin_lat = $fileRow[3];
			$city = $fileRow[4];

	$out['lat'] = $origin_lat;
	$out['lon'] = $origin_lon;
	$out['city'] = $city;
	return $out;

$distance = $input->post->radius; // Get distance
$plz = $input->post->plz; // Get PLZ

$getlatlng = plztolatlong($plz); // plz to lat and long
$lat = $getlatlng['lat']; // just for test reasons later
$lng = $getlatlng['lon']; // just for test reasons later

echo "<pre>";
echo "</pre>";
echo "LAT: " . $lat . "<br />";
echo "LONG: " . $lng . "<br />";

$radius = 6371;		// earth's radius in km = ~6371

// latitude boundaries
$maxlat = $lat + rad2deg($distance / $radius);
$maxlat = str_replace(',', '.', $maxlat); 
$minlat = $lat - rad2deg($distance / $radius);
$minlat = str_replace(',', '.', $minlat);

// longitude boundaries (longitude gets smaller when latitude increases)
$maxlng = $lng + rad2deg($distance / $radius / cos(deg2rad($lat)));
$maxlng = str_replace(',', '.', $maxlng);
$minlng = $lng - rad2deg($distance / $radius / cos(deg2rad($lat)));
$minlng = str_replace(',', '.', $minlng);

$q = "template=filialen, mapfield.lat>=$minlat, mapfield.lat<=$maxlat, mapfield.lng>=$minlng, mapfield.lng<=$maxlng";
$results = $pages->find($q);

echo "<h2>Ergebnisse</h2>";

foreach($results as $r) {
  echo "<h3>{$r->title}</h3>";
  echo "<p>{$r->mapfield->adress}</p>";
  echo "<p>{$r->filial_tel}</p>";
  echo "<p>{$r->filial_mail}</p>";
  echo "<p>{$r->filial_www}</p>";

echo $ff;





  • Like 3
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...