• Hello Fabrik Community

    Fabrik is now in the hands of the development team that brought you Fabrik for Joomla 4. We have recently transitioned the Fabrik site over to a new server and are busy trying to clean it up. We have upgraded the site to Joomla 4 and are running the latest version of Fabrik 4. We have also upgraded the Xenforo forum software to the latest version. Many of the widgets you might have been used to on the forum are no longer operational, many abandoned by the developers. We hope to bring back some of the important ones as we have time.

    Exciting times to be sure.

    The Fabrik 4.0 Official release is now available. In addition, the Fabrik codebase is now available in a public repository. See the notices about these in the announcements section

    We wish to shout out a very big Thank You to all of you who have made donations. They have really helped. But we can always use more...wink..wink..

    Also a big Thank You to those of you who have been assisting others in the forum. This takes a very big burden off of us as we work on bugs, the website and the future of Fabrik.

google map element validation (coordinates)

rtorres

Member
has anyone tryed to validate if the coordinates are IN or OUT of a series of points ? I need to validate that the user moved the indicator

my first attemp was using the value of the variable that holds the coordinates, but didn work.. Ive already search on the forums but seems like no one has needed to implement this

any ideas?
 
I actually did something very similar recently. You can do the following in a PHP validation ...

Code:
// bust the map element data into coords
$coords = FabrikString::mapStrToCoords($data);
// get the maps API key
$config = JComponentHelper::getParams('com_fabrik');
$apiKey     = $config->get('google_api_key', '');
// build the reverse geocode api url
$url = 'https://maps.googleapis.com/maps/api/geocode/json?latlng=' . $coords->lat . ',' . $coords->long . '&sensor=false&key=' . $apiKey;
// make the HTTP request
$data = @file_get_contents($url);

// if you are doing this from a local host without certs, you may need to comment out the previous line and uncomment these lines
//$aContext = array(
//    'ssl' => array(
//        'verify_peer' => false,
//    ),
//);
//$cxContext = stream_context_create($aContext);
//$data = @file_get_contents($url, false, $cxContext);

// parse the json response
$data = json_decode($data,true);
// loop around returned results, return false if we find a country code that isn't 'US'
foreach ($data['results'] as $result) {
  foreach ($result['address_components'] as $component) {
    foreach ($component['types'] as $type) {
      if ($type === 'country') {
        if ($component['short_name'] !== 'US') {
           return false;
        }
      }
    }
  }
}
// we got this far, so ... woo hoo ...
return true;

The above code should work, although it could use a little error checking on the returned response.

Replace 'US' with your desired short country code.

NOTE - you'll need to have your Google maps API key configured in Fabrik's global settings, and enable the reverse geocode API in your Google dashboard.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top