'200 Miles', 100=>'100 Miles', 50=>'50 Miles', ); if(isset($_POST['ajax'])) { if(isset($_POST['action']) && $_POST['action']=='get_nearby_stores') { if(!isset($_POST['lat']) || !isset($_POST['lng'])) { echo json_encode(array('success'=>0,'msg'=>'Coordinate not found')); exit; } // support unicode mysql_query("SET NAMES utf8"); // category filter if(!isset($_POST['products']) || $_POST['products']==""){ $category_filter = ""; } else { $category_filter = " AND cat_id='".$_POST['products']."'"; } $sql = "SELECT *, ( 3959 * ACOS( COS( RADIANS(".$_POST['lat'].") ) * COS( RADIANS( latitude ) ) * COS( RADIANS( longitude ) - RADIANS(".$_POST['lng'].") ) + SIN( RADIANS(".$_POST['lat'].") ) * SIN( RADIANS( latitude ) ) ) ) AS distance FROM stores WHERE status=1 AND approved=1 ".$category_filter." HAVING distance <= ".$_POST['distance']." ORDER BY distance ASC LIMIT 0,60"; echo json_stores_list($sql); } exit; } $errors = array(); if($_POST) { if(isset($_POST['address']) && empty($_POST['address'])) { $errors[] = 'Please enter your address'; } else { $google_api_key = ''; $region = 'us'; $xml = convertXMLtoArray($tmp); if($xml['Response']['Status']['code']=='200') { $coords = explode(',', $xml['Response']['Placemark']['Point']['coordinates']); if(isset($coords[0]) && isset($coords[1])) { $data = array( 'name'=>$v['name'], 'address'=>$v['address'], 'latitude'=>$coords[1], 'longitude'=>$coords[0] ); $sql = "SELECT *, ( 3959 * ACOS( COS( RADIANS(".$coords[1].") ) * COS( RADIANS( latitude ) ) * COS( RADIANS( longitude ) - RADIANS(".$coords[0].") ) + SIN( RADIANS(".$coords[1].") ) * SIN( RADIANS( latitude ) ) ) ) AS distance FROM stores WHERE status=1 HAVING distance <= ".$db->escape($_POST['distance'])." ORDER BY distance ASC LIMIT 0,60"; $stores = $db->get_rows($sql); if(empty($stores)) { $errors[] = 'Stores with address '.$_POST['address'].' not found.'; } } else { $errors[] = 'Address not valid'; } } else { $errors[] = 'Entered address'.$_POST['address'].' not found.'; } } } ?>