2015-08-28 47 views
1

當員工登錄時,我們需要自動檢索當前位置並插入它。這是一個在線打卡輸入/輸出系統。因此,只要確保輸入/輸出不會因其他地方的輸入/輸出而被濫用。使用http://ipinfo.io/作爲Gaurang Joshi在下面提到的我得到互聯網知識產權和緯度和logitudes.So我需要使用任何谷歌地圖庫得到具體位置?如何實現它?任何幫助。如何在codeigniter中獲取當前位置和網絡IP?

+0

請提供一個例子以及在哪裏保存你的位置? – Priyank

+0

選中此項可能對您有所幫助。 [http://theonlytutorials.com/user-current-location-ip-address-simple-php-script/] –

回答

1

服務器IP

要獲取$_SERVER['SERVER_ADDR']

本地IP服務器IP地址

要通過$_SERVER['REMOTE_ADDR']


要查找的位置根本就獲取客戶端IP:

//ipinfo grabs the ip of the person requesting 

$getloc = json_decode(file_get_contents("http://ipinfo.io/")); 

echo $getloc->city; //to get city 

如果您使用座標它像32單個字符串返回,-72所以,對於您可以使用:

$coordinates = explode(",", $getloc->loc); // -> '32,-72' becomes'32','-72' 
echo $coordinates[0]; // latitude 
echo $coordinates[1]; // longitude 
+0

這將返回互聯網IP權利除了locatoin,有沒有什麼辦法可以獲得網絡IP?所以,當用戶我們可以從其他網絡登錄來追蹤它。 –

+0

先生,還得到的位置我需要使用谷歌地圖庫?因爲上面的$ getloc->城市只是返回新加坡和確切位置沒有提到,所以我想我需要嘗試找到位置使用獲得的經度和緯度。 –

+0

你的網址是什麼意思?那個MAC地址? –

0

公共功能指數(){

$ip = $_SERVER['REMOTE_ADDR']; 
    //$location = file_get_contents('http://freegeoip.net/json/'.$_SERVER['REMOTE_ADDR']); 
    $location = file_get_contents('http://ip-api.com/json/'.$ip); 
    //print_r($location);exit; 
    $data_loc = json_decode($location); 
    $marker = array(); 
    $data = array(
       'view_file'=>'index', 
       'current_menu'=>'index', 
       'site_title' =>'site title', 
       'logo'  => 'logo', 
       'title'=>'Family Owned Pest Control', 
      ); 
    $Lat = ''; 
    $Lon = ''; 
    if(isset($_GET['searchsubmit'])) 
    { 
     $Address = $this->input->get('addr_loc'); 
     $jobtitle = $this->input->get('jobtitle'); 

     $request_url = "//maps.googleapis.com/maps/api/geocode/xml?address=".$Address."&sensor=true"; 
     $xml = simplexml_load_file($request_url) or die("url not loading"); 

     $status = $xml->status; 

     if ($status=="OK") { 
      $Lat = $xml->result->geometry->location->lat; 
      $Lon = $xml->result->geometry->location->lng; 
     } 
    } 

    if(empty($Lat) AND empty($Lon)) 
    { 
     $config['center'] = 'auto'; 
     $marker['position'] = $data_loc->lat.",". $data_loc->lon ; 
     $Lat = $data_loc->lat; 
     $Lon = $data_loc->lon; 
    } 
    else{ 
     $config['center'] ='auto'; 
     $marker['position'] = $Lat.",". $Lon ; 
    } 

    $config['zoom'] = '11'; 
    $config['places'] = TRUE; 
    $config['placesAutocompleteInputID'] = 'myPlaceTextBox'; 
    $config['placesAutocompleteBoundsMap'] = TRUE; // set results biased towards the maps viewport 
    $this->googlemaps->initialize($config); 
    $marker['infowindow_content'] = $data_loc->city.'<br>'.$data_loc->regionName.'<br>'.$data_loc->country; 
    $marker['icon'] = '//chart.apis.google.com/chart?chst=d_map_pin_letter&chld=A|9999FF|000000'; 
    $this->googlemaps->add_marker($marker); 
    $Lat1 = $Lat+0.05; 
    $Lon1 = $Lon+0.05; 
    $marker = array(); 
    $marker['position'] = $Lat1.",". $Lon1; 
    $marker['draggable'] = TRUE; 
    $marker['animation'] = 'DROP'; 
    $marker['infowindow_content'] = 'dskjfhdsjhfsd' ; 
    $marker['icon'] = '//chart.apis.google.com/chart?chst=d_map_pin_letter&chld=B|9999FF|000000'; 
    $this->googlemaps->add_marker($marker); 
    $Lat2 = $Lat1+0.05; 
    $Lon2 = $Lon1+0.05; 
    $marker = array(); 
    $marker['position'] = $Lat2.",". $Lon2; 
    $marker['draggable'] = TRUE; 
    $marker['animation'] = 'DROP'; 
    $marker['infowindow_content'] = 'dskjfhdsjdsfsdfhfsd' ; 
    $marker['icon'] = '//chart.apis.google.com/chart?chst=d_map_pin_letter&chld=C|9999FF|000000'; 
    $this->googlemaps->add_marker($marker); 


    $data['content']='content/peta'; 

    $data['map'] = $this->googlemaps->create_map(); 

    $this->template->load_index_template($data); 
}