Hướng dẫn how can i get latitude and longitude from google map in php? - làm cách nào tôi có thể lấy vĩ độ và kinh độ từ bản đồ google bằng php?

Tôi đã sử dụng AutoComplete của mã địa lý nhưng khi tôi chọn từ thả xuống, nó sẽ cho tôi LAT và Long của địa chỉ

Tôi cần kiểm tra khi LAT và Long trống sau đó từ địa chỉ được đăng, tôi phải nhận được vĩ độ và kinh độ

LAGBOX

46.5k8 Huy hiệu vàng68 Huy hiệu bạc83 Huy hiệu đồng8 gold badges68 silver badges83 bronze badges

Hỏi ngày 22 tháng 4 năm 2014 lúc 7:02Apr 22, 2014 at 7:02

2

Giả sử bạn có giá trị ẩn cho LAT và dài là Maplat & Maplong và tên trường nhập là vị trí sau đó:












extract[$_POST];
if[$mapLat =='' && $mapLong =='']{
        // Get lat long from google
        $latlong    =   get_lat_long[$location]; // create a function with the name "get_lat_long" given as below
        $map        =   explode[',' ,$latlong];
        $mapLat         =   $map[0];
        $mapLong    =   $map[1];    
}


// function to get  the address
function get_lat_long[$address]{

    $address = str_replace[" ", "+", $address];

    $json = file_get_contents["//maps.google.com/maps/api/geocode/json?address=$address&sensor=false®ion=$region"];
    $json = json_decode[$json];

    $lat = $json->{'results'}[0]->{'geometry'}->{'location'}->{'lat'};
    $long = $json->{'results'}[0]->{'geometry'}->{'location'}->{'lng'};
    return $lat.','.$long;
}

Đã trả lời ngày 22 tháng 4 năm 2014 lúc 7:09Apr 22, 2014 at 7:09

6

Sử dụng Curl CURL


Đã trả lời ngày 1 tháng 4 năm 2017 lúc 9:27Apr 1, 2017 at 9:27

Mukesh Chapagainmukesh ChapagainMukesh Chapagain

24.4K15 Huy hiệu vàng115 Huy hiệu bạc118 Huy hiệu đồng15 gold badges115 silver badges118 bronze badges

2

Tôi đã thử các giải pháp ở trên nhưng không có giải pháp nào hoạt động sau đó tôi đã cố gắng tự khắc phục vì vậy dưới đây là mã chính xác:

    $going=$this->input->post['going'];

    $address =$going; // Google HQ
    $prepAddr = str_replace[' ','+',$address];
    $apiKey = 'Add your API Key'; // Google maps now requires an API key.

    $geocode=file_get_contents['//maps.googleapis.com/maps/api/geocode/json? 
   address='.urlencode[$address].'&sensor=false&key='.$apiKey];

    //print_r[$geocode];

    $output= json_decode[$geocode];
    $latitude = $output->results[0]->geometry->location->lat;
    $longitude = $output->results[0]->geometry->location->lng;

Đã trả lời ngày 10 tháng 10 năm 2019 lúc 17:39Oct 10, 2019 at 17:39

FahadkhanfahadkhanFahadKhan

711 Huy hiệu bạc3 Huy hiệu đồng1 silver badge3 bronze badges

2

// We define our address
$address = 'Indore, MP 452001';
echo"
";
print_r[get_lat_long[$address]];

// function to get  the address
function get_lat_long[$address] {
   $array = array[];
   $geo = file_get_contents['//maps.googleapis.com/maps/api/geocode/json?address='.urlencode[$address].'&sensor=false'];

   // We convert the JSON to an array
   $geo = json_decode[$geo, true];

   // If everything is cool
   if [$geo['status'] = 'OK'] {
      $latitude = $geo['results'][0]['geometry']['location']['lat'];
      $longitude = $geo['results'][0]['geometry']['location']['lng'];
      $array = array['lat'=> $latitude ,'lng'=>$longitude];
   }

   return $array;
}

Cho đến khi Helge

9.1152 huy hiệu vàng40 Huy hiệu bạc56 Huy hiệu đồng2 gold badges40 silver badges56 bronze badges

Đã trả lời ngày 13 tháng 7 năm 2016 lúc 7:49Jul 13, 2016 at 7:49

1

Hãy thử điều này để lấy địa chỉ:

xxx

1.1331 Huy hiệu vàng11 Huy hiệu bạc23 Huy hiệu đồng1 gold badge11 silver badges23 bronze badges

Đã trả lời ngày 3 tháng 12 năm 2014 lúc 6:03Dec 3, 2014 at 6:03

1

Bài Viết Liên Quan

Chủ Đề