Thursday, March 7, 2019

Google maps: find location by only text address

$job = $this->JobPostInfo->find('first', array(
'conditions' => array('JobPostInfo.id' => 3),
'recursive' => -1,
'fields' => array('JobPostInfo.user_id'),
));
$employerLocationInfo = $this->EmployerContactDetail->find('first', array(
'conditions' => array('EmployerContactDetail.user_id' => $job['JobPostInfo']['user_id']),
'recursive' => -1,
'fields' => array('EmployerContactDetail.address'),
));
$split_address = preg_split('/[\ \n\,]+/', $employerLocationInfo['EmployerContactDetail']['address']);
$str = '';
foreach($split_address as $value){
$value = str_replace(' ', '', $value);
$str .= '+'.$value;
}
$str= trim($str,'+');
$ch = curl_init();
$headers = array(
'Accept: application/json',
'Content-Type: application/json',
);
curl_setopt($ch, CURLOPT_URL, "https://maps.googleapis.com/maps/api/geocode/json?address=".$str."&sensor=true&key=AIzaSyBnPOKe9dLW_8PfE78ubqrJ4_SQDyOgPsg");
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$json = curl_exec($ch);
curl_close ($ch);
// $fullurl = "https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=true&key=AIzaSyBnPOKe9dLW_8PfE78ubqrJ4_SQDyOgPsg";
// $string = file_get_contents($fullurl); // get json content
// $json = json_decode($string, true); //json decoder
$response = json_decode($json, true);
$mapsLatLongData = $response['results'][0]['geometry']['location'];
$this->set(compact('mapsLatLongData'));

Wednesday, January 16, 2019

DateRangePicker : Date Range Picker how to fire an event on entering a date

7
this section is the callback function:
function(start, end) {
    $('#dateRange span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
}
you can add any code you want in this function to execute when a user selects a date. you could even define a callback function yourself and pass it to the daterange picker method.
example:
function myCallback(start, end) {
    $('#dateRange span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
    alert('hello world'); //etc, your code here
}
// attach daterangepicker plugin
$('#dateRange').daterangepicker(options, myCallback);
you also could even define your own custom event handler and trigger it in the callback as well.
example
$(document).on('myCustomEvent', function () {
    // your code here
});

$('#dateRange').daterangepicker({
// .. //
function(start, end) {
    $('#dateRange span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
    $(document).trigger('myCustomEvent');
});
  • 1
    Thank you so much. That helped a lot! – Linda Keating Sep 1 '13 at 20:53
  • I am using cakephp and same daterange picker for my project, how i can send start and end date to Controller using this myCustonevetnt? – Aryan Sep 30 '13 at 16:32 
  • 1
    @Neil S, I am facing one issue when I don't change the default selected value in the daterangepicker, when clicking on apply button the callback function is not executed. Is there any solution to that. – tejashsoni111 May 14 '15 at 7:26

10
From daterangepicker.com:
$('#daterange').on('apply.daterangepicker', function(ev, picker) {
    alert ('hello');
});


https://stackoverflow.com/questions/18562616/date-range-picker-how-to-fire-an-event-on-entering-a-date