Làm cách nào để hiển thị vị trí trên Google Maps bằng vĩ độ và kinh độ trong php?

Chúng tôi đã tạo một lớp trợ giúp để nhanh chóng bắt đầu sử dụng Google Geocoding API. Hướng dẫn rất đơn giản. Đặt tệp lớp [bạn có thể sao chép nó bên dưới từ ý chính] ở đâu đó trong dự án của bạn. Cập nhật đường dẫn đến lớp trợ giúp, địa chỉ và khóa API trong mã bên dưới

Trang này mô tả dịch vụ phía máy khách có sẵn với Maps JavaScript API. Nếu bạn muốn làm việc với các dịch vụ web của Google Maps trên máy chủ của mình, hãy xem Nút. js Ứng dụng khách cho Dịch vụ Google Maps. Trang tại liên kết đó cũng giới thiệu Máy khách Java, Máy khách Python và Máy khách Go cho Dịch vụ Google Maps

Tổng quan

Ngoài ra, hãy xem Tham chiếu API JavaScript của Maps. mã hóa địa lý

Mã hóa địa lý là quá trình chuyển đổi địa chỉ [như "1600 Amphitheatre Parkway, Mountain View, CA"] thành tọa độ địa lý [như vĩ độ 37. 423021 và kinh độ -122. 083739], mà bạn có thể sử dụng để đánh dấu hoặc định vị bản đồ

Mã hóa địa lý ngược là quá trình chuyển đổi tọa độ địa lý thành địa chỉ mà con người có thể đọc được [xem phần ]

Bạn cũng có thể sử dụng trình mã hóa địa lý để tìm địa chỉ cho một

API JavaScript của Maps cung cấp một lớp Trình mã hóa địa lý để mã hóa địa lý và đảo ngược mã hóa địa lý một cách linh hoạt từ đầu vào của người dùng. Thay vào đó, nếu bạn muốn mã hóa địa lý các địa chỉ tĩnh, đã biết, hãy xem dịch vụ web Mã hóa địa lý

Bắt đầu

Trước khi sử dụng dịch vụ Mã hóa địa lý trong API JavaScript của Maps, trước tiên hãy đảm bảo rằng API mã hóa địa lý được bật trong Google Cloud Console, trong cùng một dự án mà bạn đã thiết lập cho API JavaScript của Maps

Để xem danh sách các API đã bật của bạn

  1. Truy cập Google Cloud Console
  2. Nhấp vào nút Chọn dự án, sau đó chọn cùng một dự án mà bạn đã thiết lập cho API JavaScript của Maps và nhấp vào Mở
  3. Từ danh sách API trên Trang tổng quan, hãy tìm API mã hóa địa lý
  4. Nếu bạn thấy API trong danh sách, thì bạn đã hoàn tất. Nếu API không được liệt kê, hãy kích hoạt nó
    1. Ở đầu trang, chọn BẬT API để hiển thị tab Thư viện. Ngoài ra, từ menu bên trái, chọn Thư viện
    2. Tìm kiếm Geocoding API, sau đó chọn nó từ danh sách kết quả
    3. Chọn BẬT. Khi quá trình kết thúc, API mã hóa địa lý sẽ xuất hiện trong danh sách API trên Trang tổng quan

Giá cả và chính sách

định giá

Có hiệu lực từ ngày 16 tháng 7 năm 2018, gói giá mới trả theo mức sử dụng đã có hiệu lực cho Bản đồ, Tuyến đường và Địa điểm. Để tìm hiểu thêm về giới hạn sử dụng và định giá mới cho việc bạn sử dụng dịch vụ Mã hóa địa lý JavaScript, hãy xem phần Sử dụng và thanh toán cho API mã hóa địa lý

chính sách

Việc sử dụng dịch vụ Mã hóa địa lý phải tuân theo các chính sách được mô tả cho API mã hóa địa lý

Yêu cầu mã hóa địa lý

Việc truy cập dịch vụ Mã hóa địa lý là không đồng bộ, do API Google Maps cần thực hiện lệnh gọi đến máy chủ bên ngoài. Vì lý do đó, bạn cần chuyển một phương thức gọi lại để thực thi sau khi hoàn thành yêu cầu. Phương thức gọi lại này xử lý [các] kết quả. Lưu ý rằng trình mã hóa địa lý có thể trả về nhiều kết quả

Bạn truy cập dịch vụ mã hóa địa lý API Google Maps trong mã của mình thông qua đối tượng hàm tạo

results[]: {
 types[]: string,
 formatted_address: string,
 address_components[]: {
   short_name: string,
   long_name: string,
   postcode_localities[]: string,
   types[]: string
 },
 partial_match: boolean,
 place_id: string,
 postcode_localities[]: string,
 geometry: {
   location: LatLng,
   location_type: GeocoderLocationType
   viewport: LatLngBounds,
   bounds: LatLngBounds
 }
}
3. Phương thức
results[]: {
 types[]: string,
 formatted_address: string,
 address_components[]: {
   short_name: string,
   long_name: string,
   postcode_localities[]: string,
   types[]: string
 },
 partial_match: boolean,
 place_id: string,
 postcode_localities[]: string,
 geometry: {
   location: LatLng,
   location_type: GeocoderLocationType
   viewport: LatLngBounds,
   bounds: LatLngBounds
 }
}
4 khởi tạo một yêu cầu tới dịch vụ mã hóa địa lý, chuyển cho nó một đối tượng
results[]: {
 types[]: string,
 formatted_address: string,
 address_components[]: {
   short_name: string,
   long_name: string,
   postcode_localities[]: string,
   types[]: string
 },
 partial_match: boolean,
 place_id: string,
 postcode_localities[]: string,
 geometry: {
   location: LatLng,
   location_type: GeocoderLocationType
   viewport: LatLngBounds,
   bounds: LatLngBounds
 }
}
5 có chứa các thuật ngữ đầu vào và một phương thức gọi lại để thực thi khi nhận được phản hồi

Đối tượng

results[]: {
 types[]: string,
 formatted_address: string,
 address_components[]: {
   short_name: string,
   long_name: string,
   postcode_localities[]: string,
   types[]: string
 },
 partial_match: boolean,
 place_id: string,
 postcode_localities[]: string,
 geometry: {
   location: LatLng,
   location_type: GeocoderLocationType
   viewport: LatLngBounds,
   bounds: LatLngBounds
 }
}
5 theo nghĩa đen chứa các trường sau

{
 address: string,
 location: LatLng,
 placeId: string,
 bounds: LatLngBounds,
 componentRestrictions: GeocoderComponentRestrictions,
 region: string
}

Thông số bắt buộc. Bạn phải cung cấp một và chỉ một trong các trường sau

  • results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    7 — Địa chỉ mà bạn muốn mã hóa địa lý.
         hoặc
    results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    8 —
    results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    9 [hoặc
      var geocoder;
      var map;
      function initialize[] {
        geocoder = new google.maps.Geocoder[];
        var latlng = new google.maps.LatLng[-34.397, 150.644];
        var mapOptions = {
          zoom: 8,
          center: latlng
        }
        map = new google.maps.Map[document.getElementById['map'], mapOptions];
      }
    
      function codeAddress[] {
        var address = document.getElementById['address'].value;
        geocoder.geocode[ { 'address': address}, function[results, status] {
          if [status == 'OK'] {
            map.setCenter[results[0].geometry.location];
            var marker = new google.maps.Marker[{
                map: map,
                position: results[0].geometry.location
            }];
          } else {
            alert['Geocode was not successful for the following reason: ' + status];
          }
        }];
      }
    
    
     
    0] mà bạn muốn có được địa chỉ gần nhất mà con người có thể đọc được. Trình mã hóa địa lý thực hiện mã địa lý đảo ngược. Xem để biết thêm thông tin.
         hoặc
      var geocoder;
      var map;
      function initialize[] {
        geocoder = new google.maps.Geocoder[];
        var latlng = new google.maps.LatLng[-34.397, 150.644];
        var mapOptions = {
          zoom: 8,
          center: latlng
        }
        map = new google.maps.Map[document.getElementById['map'], mapOptions];
      }
    
      function codeAddress[] {
        var address = document.getElementById['address'].value;
        geocoder.geocode[ { 'address': address}, function[results, status] {
          if [status == 'OK'] {
            map.setCenter[results[0].geometry.location];
            var marker = new google.maps.Marker[{
                map: map,
                position: results[0].geometry.location
            }];
          } else {
            alert['Geocode was not successful for the following reason: ' + status];
          }
        }];
      }
    
    
     
    1 — ID địa điểm của địa điểm mà bạn muốn lấy địa chỉ gần nhất, mà con người có thể đọc được. Xem thêm về.

thông số tùy chọn

  •   var geocoder;
      var map;
      function initialize[] {
        geocoder = new google.maps.Geocoder[];
        var latlng = new google.maps.LatLng[-34.397, 150.644];
        var mapOptions = {
          zoom: 8,
          center: latlng
        }
        map = new google.maps.Map[document.getElementById['map'], mapOptions];
      }
    
      function codeAddress[] {
        var address = document.getElementById['address'].value;
        geocoder.geocode[ { 'address': address}, function[results, status] {
          if [status == 'OK'] {
            map.setCenter[results[0].geometry.location];
            var marker = new google.maps.Marker[{
                map: map,
                position: results[0].geometry.location
            }];
          } else {
            alert['Geocode was not successful for the following reason: ' + status];
          }
        }];
      }
    
    
     
    2 —
      var geocoder;
      var map;
      function initialize[] {
        geocoder = new google.maps.Geocoder[];
        var latlng = new google.maps.LatLng[-34.397, 150.644];
        var mapOptions = {
          zoom: 8,
          center: latlng
        }
        map = new google.maps.Map[document.getElementById['map'], mapOptions];
      }
    
      function codeAddress[] {
        var address = document.getElementById['address'].value;
        geocoder.geocode[ { 'address': address}, function[results, status] {
          if [status == 'OK'] {
            map.setCenter[results[0].geometry.location];
            var marker = new google.maps.Marker[{
                map: map,
                position: results[0].geometry.location
            }];
          } else {
            alert['Geocode was not successful for the following reason: ' + status];
          }
        }];
      }
    
    
     
    3 trong đó mã hóa địa lý thiên vị cho kết quả nổi bật hơn. Tham số
      var geocoder;
      var map;
      function initialize[] {
        geocoder = new google.maps.Geocoder[];
        var latlng = new google.maps.LatLng[-34.397, 150.644];
        var mapOptions = {
          zoom: 8,
          center: latlng
        }
        map = new google.maps.Map[document.getElementById['map'], mapOptions];
      }
    
      function codeAddress[] {
        var address = document.getElementById['address'].value;
        geocoder.geocode[ { 'address': address}, function[results, status] {
          if [status == 'OK'] {
            map.setCenter[results[0].geometry.location];
            var marker = new google.maps.Marker[{
                map: map,
                position: results[0].geometry.location
            }];
          } else {
            alert['Geocode was not successful for the following reason: ' + status];
          }
        }];
      }
    
    
     
    2 sẽ chỉ ảnh hưởng chứ không hạn chế hoàn toàn kết quả từ bộ mã hóa địa lý. Xem thêm thông tin về bên dưới
  •   var geocoder;
      var map;
      function initialize[] {
        geocoder = new google.maps.Geocoder[];
        var latlng = new google.maps.LatLng[-34.397, 150.644];
        var mapOptions = {
          zoom: 8,
          center: latlng
        }
        map = new google.maps.Map[document.getElementById['map'], mapOptions];
      }
    
      function codeAddress[] {
        var address = document.getElementById['address'].value;
        geocoder.geocode[ { 'address': address}, function[results, status] {
          if [status == 'OK'] {
            map.setCenter[results[0].geometry.location];
            var marker = new google.maps.Marker[{
                map: map,
                position: results[0].geometry.location
            }];
          } else {
            alert['Geocode was not successful for the following reason: ' + status];
          }
        }];
      }
    
    
     
    5 — Được sử dụng để giới hạn kết quả trong một khu vực cụ thể. Xem thêm thông tin về bên dưới
  •   var geocoder;
      var map;
      function initialize[] {
        geocoder = new google.maps.Geocoder[];
        var latlng = new google.maps.LatLng[-34.397, 150.644];
        var mapOptions = {
          zoom: 8,
          center: latlng
        }
        map = new google.maps.Map[document.getElementById['map'], mapOptions];
      }
    
      function codeAddress[] {
        var address = document.getElementById['address'].value;
        geocoder.geocode[ { 'address': address}, function[results, status] {
          if [status == 'OK'] {
            map.setCenter[results[0].geometry.location];
            var marker = new google.maps.Marker[{
                map: map,
                position: results[0].geometry.location
            }];
          } else {
            alert['Geocode was not successful for the following reason: ' + status];
          }
        }];
      }
    
    
     
    6 — Mã vùng, được chỉ định dưới dạng thẻ phụ vùng Unicode gồm hai ký tự [không phải số] được chỉ định. Trong hầu hết các trường hợp, các thẻ này ánh xạ trực tiếp tới các giá trị hai ký tự ccTLD ["miền cấp cao nhất"] quen thuộc. Tham số
      var geocoder;
      var map;
      function initialize[] {
        geocoder = new google.maps.Geocoder[];
        var latlng = new google.maps.LatLng[-34.397, 150.644];
        var mapOptions = {
          zoom: 8,
          center: latlng
        }
        map = new google.maps.Map[document.getElementById['map'], mapOptions];
      }
    
      function codeAddress[] {
        var address = document.getElementById['address'].value;
        geocoder.geocode[ { 'address': address}, function[results, status] {
          if [status == 'OK'] {
            map.setCenter[results[0].geometry.location];
            var marker = new google.maps.Marker[{
                map: map,
                position: results[0].geometry.location
            }];
          } else {
            alert['Geocode was not successful for the following reason: ' + status];
          }
        }];
      }
    
    
     
    6 sẽ chỉ ảnh hưởng chứ không hạn chế hoàn toàn kết quả từ bộ mã hóa địa lý. Xem thêm thông tin về bên dưới

Phản hồi mã hóa địa lý

Dịch vụ Mã hóa địa lý yêu cầu phương thức gọi lại để thực thi khi truy xuất kết quả của trình mã hóa địa lý. Cuộc gọi lại này phải truyền hai tham số để giữ mã

  var geocoder;
  var map;
  function initialize[] {
    geocoder = new google.maps.Geocoder[];
    var latlng = new google.maps.LatLng[-34.397, 150.644];
    var mapOptions = {
      zoom: 8,
      center: latlng
    }
    map = new google.maps.Map[document.getElementById['map'], mapOptions];
  }

  function codeAddress[] {
    var address = document.getElementById['address'].value;
    geocoder.geocode[ { 'address': address}, function[results, status] {
      if [status == 'OK'] {
        map.setCenter[results[0].geometry.location];
        var marker = new google.maps.Marker[{
            map: map,
            position: results[0].geometry.location
        }];
      } else {
        alert['Geocode was not successful for the following reason: ' + status];
      }
    }];
  }


 
8 và mã
  var geocoder;
  var map;
  function initialize[] {
    geocoder = new google.maps.Geocoder[];
    var latlng = new google.maps.LatLng[-34.397, 150.644];
    var mapOptions = {
      zoom: 8,
      center: latlng
    }
    map = new google.maps.Map[document.getElementById['map'], mapOptions];
  }

  function codeAddress[] {
    var address = document.getElementById['address'].value;
    geocoder.geocode[ { 'address': address}, function[results, status] {
      if [status == 'OK'] {
        map.setCenter[results[0].geometry.location];
        var marker = new google.maps.Marker[{
            map: map,
            position: results[0].geometry.location
        }];
      } else {
        alert['Geocode was not successful for the following reason: ' + status];
      }
    }];
  }


 
9, theo thứ tự đó

Kết quả mã hóa địa lý

Đối tượng

results[]: {
 types[]: string,
 formatted_address: string,
 address_components[]: {
   short_name: string,
   long_name: string,
   postcode_localities[]: string,
   types[]: string
 },
 partial_match: boolean,
 place_id: string,
 postcode_localities[]: string,
 geometry: {
   location: LatLng,
   location_type: GeocoderLocationType
   viewport: LatLngBounds,
   bounds: LatLngBounds
 }
}
80 đại diện cho một kết quả mã hóa địa lý duy nhất. Yêu cầu mã địa lý có thể trả về nhiều đối tượng kết quả

results[]: {
 types[]: string,
 formatted_address: string,
 address_components[]: {
   short_name: string,
   long_name: string,
   postcode_localities[]: string,
   types[]: string
 },
 partial_match: boolean,
 place_id: string,
 postcode_localities[]: string,
 geometry: {
   location: LatLng,
   location_type: GeocoderLocationType
   viewport: LatLngBounds,
   bounds: LatLngBounds
 }
}

Những lĩnh vực này được giải thích dưới đây

  • results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    81 là một mảng cho biết loại địa chỉ của kết quả trả về. Mảng này chứa một tập hợp gồm 0 hoặc nhiều thẻ xác định loại tính năng được trả về trong kết quả. Ví dụ: mã địa lý của "Chicago" trả về "địa phương" cho biết "Chicago" là một thành phố và cũng trả về "chính trị" cho biết đó là một thực thể chính trị. Xem thêm thông tin về bên dưới
  • results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    82 là một chuỗi chứa địa chỉ con người có thể đọc được của vị trí này

    Thường thì địa chỉ này tương đương với địa chỉ bưu chính. Lưu ý rằng một số quốc gia, chẳng hạn như Vương quốc Anh, không cho phép phân phối địa chỉ bưu chính thực do hạn chế cấp phép

    Địa chỉ được định dạng bao gồm một hoặc nhiều thành phần địa chỉ một cách hợp lý. Ví dụ: địa chỉ "111 8th Avenue, New York, NY" bao gồm các thành phần sau. "111" [số đường], "8th Avenue" [tuyến đường], "New York" [thành phố] và "NY" [tiểu bang của Hoa Kỳ]

    Không phân tích cú pháp địa chỉ được định dạng theo chương trình. Thay vào đó, bạn nên sử dụng các thành phần địa chỉ riêng lẻ mà phản hồi API bao gồm ngoài trường địa chỉ được định dạng

  • results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    83 là một mảng chứa các thành phần riêng biệt áp dụng cho địa chỉ này

    Mỗi thành phần địa chỉ thường chứa các trường sau

    • results[]: {
       types[]: string,
       formatted_address: string,
       address_components[]: {
         short_name: string,
         long_name: string,
         postcode_localities[]: string,
         types[]: string
       },
       partial_match: boolean,
       place_id: string,
       postcode_localities[]: string,
       geometry: {
         location: LatLng,
         location_type: GeocoderLocationType
         viewport: LatLngBounds,
         bounds: LatLngBounds
       }
      }
      
      81 là một mảng cho biết loại thành phần địa chỉ. Xem danh sách các loại được hỗ trợ
    • results[]: {
       types[]: string,
       formatted_address: string,
       address_components[]: {
         short_name: string,
         long_name: string,
         postcode_localities[]: string,
         types[]: string
       },
       partial_match: boolean,
       place_id: string,
       postcode_localities[]: string,
       geometry: {
         location: LatLng,
         location_type: GeocoderLocationType
         viewport: LatLngBounds,
         bounds: LatLngBounds
       }
      }
      
      85 là mô tả toàn văn hoặc tên của thành phần địa chỉ do Bộ mã hóa địa lý trả về
    • results[]: {
       types[]: string,
       formatted_address: string,
       address_components[]: {
         short_name: string,
         long_name: string,
         postcode_localities[]: string,
         types[]: string
       },
       partial_match: boolean,
       place_id: string,
       postcode_localities[]: string,
       geometry: {
         location: LatLng,
         location_type: GeocoderLocationType
         viewport: LatLngBounds,
         bounds: LatLngBounds
       }
      }
      
      86 là tên văn bản viết tắt của thành phần địa chỉ, nếu có. Ví dụ: một thành phần địa chỉ cho bang Alaska có thể có
      results[]: {
       types[]: string,
       formatted_address: string,
       address_components[]: {
         short_name: string,
         long_name: string,
         postcode_localities[]: string,
         types[]: string
       },
       partial_match: boolean,
       place_id: string,
       postcode_localities[]: string,
       geometry: {
         location: LatLng,
         location_type: GeocoderLocationType
         viewport: LatLngBounds,
         bounds: LatLngBounds
       }
      }
      
      85 của "Alaska" và
      results[]: {
       types[]: string,
       formatted_address: string,
       address_components[]: {
         short_name: string,
         long_name: string,
         postcode_localities[]: string,
         types[]: string
       },
       partial_match: boolean,
       place_id: string,
       postcode_localities[]: string,
       geometry: {
         location: LatLng,
         location_type: GeocoderLocationType
         viewport: LatLngBounds,
         bounds: LatLngBounds
       }
      }
      
      86 của "AK" bằng cách sử dụng 2 ký tự viết tắt của bưu chính

    Lưu ý các sự kiện sau về mảng

    results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    83

    • Mảng các thành phần địa chỉ có thể chứa nhiều thành phần hơn
      results[]: {
       types[]: string,
       formatted_address: string,
       address_components[]: {
         short_name: string,
         long_name: string,
         postcode_localities[]: string,
         types[]: string
       },
       partial_match: boolean,
       place_id: string,
       postcode_localities[]: string,
       geometry: {
         location: LatLng,
         location_type: GeocoderLocationType
         viewport: LatLngBounds,
         bounds: LatLngBounds
       }
      }
      
      82
    • Mảng không nhất thiết phải bao gồm tất cả các thực thể chính trị có chứa địa chỉ, ngoại trừ những thực thể có trong
      results[]: {
       types[]: string,
       formatted_address: string,
       address_components[]: {
         short_name: string,
         long_name: string,
         postcode_localities[]: string,
         types[]: string
       },
       partial_match: boolean,
       place_id: string,
       postcode_localities[]: string,
       geometry: {
         location: LatLng,
         location_type: GeocoderLocationType
         viewport: LatLngBounds,
         bounds: LatLngBounds
       }
      }
      
      82. Để truy xuất tất cả các thực thể chính trị có chứa một địa chỉ cụ thể, bạn nên sử dụng mã hóa địa lý ngược, chuyển vĩ độ/kinh độ của địa chỉ làm tham số cho yêu cầu
    • Định dạng của phản hồi không được đảm bảo giữ nguyên giữa các yêu cầu. Đặc biệt, số lượng
      results[]: {
       types[]: string,
       formatted_address: string,
       address_components[]: {
         short_name: string,
         long_name: string,
         postcode_localities[]: string,
         types[]: string
       },
       partial_match: boolean,
       place_id: string,
       postcode_localities[]: string,
       geometry: {
         location: LatLng,
         location_type: GeocoderLocationType
         viewport: LatLngBounds,
         bounds: LatLngBounds
       }
      }
      
      12 thay đổi tùy theo địa chỉ được yêu cầu và có thể thay đổi theo thời gian đối với cùng một địa chỉ. Một thành phần có thể thay đổi vị trí trong mảng. Loại thành phần có thể thay đổi. Một thành phần cụ thể có thể bị thiếu trong phản hồi sau này

    Xem thêm thông tin về bên dưới

  • results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    13 chỉ ra rằng bộ mã hóa địa lý đã không trả lại kết quả khớp chính xác cho yêu cầu ban đầu, mặc dù nó có thể khớp với một phần của địa chỉ được yêu cầu. Bạn có thể muốn kiểm tra yêu cầu ban đầu về lỗi chính tả và/hoặc địa chỉ không đầy đủ

    Các đối sánh một phần thường xảy ra nhất đối với các địa chỉ đường phố không tồn tại trong địa phương mà bạn chuyển đến trong yêu cầu. Các kết quả trùng khớp một phần cũng có thể được trả lại khi một yêu cầu khớp với hai hoặc nhiều vị trí trong cùng một địa phương. Ví dụ: "Hillpar St, Bristol, UK" sẽ trả về kết quả khớp một phần cho cả Phố Henry và Phố Henrietta. Lưu ý rằng nếu một yêu cầu bao gồm một thành phần địa chỉ sai chính tả, thì dịch vụ mã hóa địa lý có thể đề xuất một địa chỉ thay thế. Các đề xuất được kích hoạt theo cách này cũng sẽ được đánh dấu là khớp một phần

  • results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    14 là mã định danh duy nhất của một địa điểm, có thể được sử dụng với các API Google khác. Ví dụ: bạn có thể sử dụng
    results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    14 với thư viện API Google Địa điểm để nhận thông tin chi tiết về doanh nghiệp địa phương, chẳng hạn như số điện thoại, giờ mở cửa, đánh giá của người dùng, v.v. Xem tổng quan về ID địa điểm
  • results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    16 là một mảng biểu thị tất cả các địa phương có trong một mã bưu chính và chỉ xuất hiện khi kết quả là một mã bưu chính chứa nhiều địa phương
  • results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    17 chứa các thông tin sau

    • results[]: {
       types[]: string,
       formatted_address: string,
       address_components[]: {
         short_name: string,
         long_name: string,
         postcode_localities[]: string,
         types[]: string
       },
       partial_match: boolean,
       place_id: string,
       postcode_localities[]: string,
       geometry: {
         location: LatLng,
         location_type: GeocoderLocationType
         viewport: LatLngBounds,
         bounds: LatLngBounds
       }
      }
      
      8 chứa giá trị kinh độ, vĩ độ được mã hóa địa lý. Lưu ý rằng chúng tôi trả lại vị trí này dưới dạng đối tượng
      results[]: {
       types[]: string,
       formatted_address: string,
       address_components[]: {
         short_name: string,
         long_name: string,
         postcode_localities[]: string,
         types[]: string
       },
       partial_match: boolean,
       place_id: string,
       postcode_localities[]: string,
       geometry: {
         location: LatLng,
         location_type: GeocoderLocationType
         viewport: LatLngBounds,
         bounds: LatLngBounds
       }
      }
      
      9, không phải dưới dạng chuỗi được định dạng
    • results[]: {
       types[]: string,
       formatted_address: string,
       address_components[]: {
         short_name: string,
         long_name: string,
         postcode_localities[]: string,
         types[]: string
       },
       partial_match: boolean,
       place_id: string,
       postcode_localities[]: string,
       geometry: {
         location: LatLng,
         location_type: GeocoderLocationType
         viewport: LatLngBounds,
         bounds: LatLngBounds
       }
      }
      
      90 lưu trữ dữ liệu bổ sung về vị trí đã chỉ định. Các giá trị sau hiện đang được hỗ trợ
      • results[]: {
         types[]: string,
         formatted_address: string,
         address_components[]: {
           short_name: string,
           long_name: string,
           postcode_localities[]: string,
           types[]: string
         },
         partial_match: boolean,
         place_id: string,
         postcode_localities[]: string,
         geometry: {
           location: LatLng,
           location_type: GeocoderLocationType
           viewport: LatLngBounds,
           bounds: LatLngBounds
         }
        }
        
        91 chỉ ra rằng kết quả trả về phản ánh một mã địa lý chính xác
      • results[]: {
         types[]: string,
         formatted_address: string,
         address_components[]: {
           short_name: string,
           long_name: string,
           postcode_localities[]: string,
           types[]: string
         },
         partial_match: boolean,
         place_id: string,
         postcode_localities[]: string,
         geometry: {
           location: LatLng,
           location_type: GeocoderLocationType
           viewport: LatLngBounds,
           bounds: LatLngBounds
         }
        }
        
        92 chỉ ra rằng kết quả trả về phản ánh giá trị gần đúng [thường là trên đường] được nội suy giữa hai điểm chính xác [chẳng hạn như giao lộ]. Các kết quả được nội suy thường được trả về khi không có mã địa lý trên mái nhà cho một địa chỉ đường phố
      • results[]: {
         types[]: string,
         formatted_address: string,
         address_components[]: {
           short_name: string,
           long_name: string,
           postcode_localities[]: string,
           types[]: string
         },
         partial_match: boolean,
         place_id: string,
         postcode_localities[]: string,
         geometry: {
           location: LatLng,
           location_type: GeocoderLocationType
           viewport: LatLngBounds,
           bounds: LatLngBounds
         }
        }
        
        93 chỉ ra rằng kết quả trả về là tâm hình học của kết quả, chẳng hạn như đa tuyến [ví dụ: đường phố] hoặc đa giác [vùng]
      • results[]: {
         types[]: string,
         formatted_address: string,
         address_components[]: {
           short_name: string,
           long_name: string,
           postcode_localities[]: string,
           types[]: string
         },
         partial_match: boolean,
         place_id: string,
         postcode_localities[]: string,
         geometry: {
           location: LatLng,
           location_type: GeocoderLocationType
           viewport: LatLngBounds,
           bounds: LatLngBounds
         }
        }
        
        94 chỉ ra rằng kết quả trả về là gần đúng

    • results[]: {
       types[]: string,
       formatted_address: string,
       address_components[]: {
         short_name: string,
         long_name: string,
         postcode_localities[]: string,
         types[]: string
       },
       partial_match: boolean,
       place_id: string,
       postcode_localities[]: string,
       geometry: {
         location: LatLng,
         location_type: GeocoderLocationType
         viewport: LatLngBounds,
         bounds: LatLngBounds
       }
      }
      
      95 lưu trữ chế độ xem được đề xuất cho kết quả trả về
    •   var geocoder;
        var map;
        function initialize[] {
          geocoder = new google.maps.Geocoder[];
          var latlng = new google.maps.LatLng[-34.397, 150.644];
          var mapOptions = {
            zoom: 8,
            center: latlng
          }
          map = new google.maps.Map[document.getElementById['map'], mapOptions];
        }
      
        function codeAddress[] {
          var address = document.getElementById['address'].value;
          geocoder.geocode[ { 'address': address}, function[results, status] {
            if [status == 'OK'] {
              map.setCenter[results[0].geometry.location];
              var marker = new google.maps.Marker[{
                  map: map,
                  position: results[0].geometry.location
              }];
            } else {
              alert['Geocode was not successful for the following reason: ' + status];
            }
          }];
        }
      
      
       
      2 [được trả về tùy chọn] lưu trữ
      results[]: {
       types[]: string,
       formatted_address: string,
       address_components[]: {
         short_name: string,
         long_name: string,
         postcode_localities[]: string,
         types[]: string
       },
       partial_match: boolean,
       place_id: string,
       postcode_localities[]: string,
       geometry: {
         location: LatLng,
         location_type: GeocoderLocationType
         viewport: LatLngBounds,
         bounds: LatLngBounds
       }
      }
      
      97 có thể chứa đầy đủ kết quả trả về. Lưu ý rằng các giới hạn này có thể không khớp với chế độ xem được đề xuất. [Ví dụ: San Francisco bao gồm Quần đảo Farallon, về mặt kỹ thuật là một phần của thành phố, nhưng sẽ không được trả lại trong chế độ xem. ]

Các địa chỉ sẽ được Trình mã hóa địa lý trả về bằng cài đặt ngôn ngữ ưa thích của trình duyệt hoặc ngôn ngữ được chỉ định khi tải API JavaScript bằng tham số

results[]: {
 types[]: string,
 formatted_address: string,
 address_components[]: {
   short_name: string,
   long_name: string,
   postcode_localities[]: string,
   types[]: string
 },
 partial_match: boolean,
 place_id: string,
 postcode_localities[]: string,
 geometry: {
   location: LatLng,
   location_type: GeocoderLocationType
   viewport: LatLngBounds,
   bounds: LatLngBounds
 }
}
98. [Để biết thêm thông tin, xem Bản địa hóa. ]

Các loại địa chỉ và các loại thành phần địa chỉ

Mảng

results[]: {
 types[]: string,
 formatted_address: string,
 address_components[]: {
   short_name: string,
   long_name: string,
   postcode_localities[]: string,
   types[]: string
 },
 partial_match: boolean,
 place_id: string,
 postcode_localities[]: string,
 geometry: {
   location: LatLng,
   location_type: GeocoderLocationType
   viewport: LatLngBounds,
   bounds: LatLngBounds
 }
}
81 trong biểu thị loại địa chỉ. Mảng
results[]: {
 types[]: string,
 formatted_address: string,
 address_components[]: {
   short_name: string,
   long_name: string,
   postcode_localities[]: string,
   types[]: string
 },
 partial_match: boolean,
 place_id: string,
 postcode_localities[]: string,
 geometry: {
   location: LatLng,
   location_type: GeocoderLocationType
   viewport: LatLngBounds,
   bounds: LatLngBounds
 }
}
81 cũng có thể được trả về trong a để chỉ ra loại của thành phần địa chỉ cụ thể. Địa chỉ được bộ mã hóa địa lý trả về có thể có nhiều loại; . Ví dụ: nhiều thành phố được gắn thẻ loại
results[]: {
 types[]: string,
 formatted_address: string,
 address_components[]: {
   short_name: string,
   long_name: string,
   postcode_localities[]: string,
   types[]: string
 },
 partial_match: boolean,
 place_id: string,
 postcode_localities[]: string,
 geometry: {
   location: LatLng,
   location_type: GeocoderLocationType
   viewport: LatLngBounds,
   bounds: LatLngBounds
 }
}
01 và
results[]: {
 types[]: string,
 formatted_address: string,
 address_components[]: {
   short_name: string,
   long_name: string,
   postcode_localities[]: string,
   types[]: string
 },
 partial_match: boolean,
 place_id: string,
 postcode_localities[]: string,
 geometry: {
   location: LatLng,
   location_type: GeocoderLocationType
   viewport: LatLngBounds,
   bounds: LatLngBounds
 }
}
02

Các loại sau đây được bộ mã hóa địa lý hỗ trợ và trả về ở cả loại địa chỉ và loại thành phần địa chỉ

  • results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    03 chỉ ra một địa chỉ đường phố chính xác
  • results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    04 cho biết tuyến đường được đặt tên [chẳng hạn như "US 101"]
  • results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    05 cho biết giao lộ chính, thường là của hai con đường lớn
  • results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    01 chỉ ra một thực thể chính trị. Thông thường, loại này chỉ ra một đa giác của một số cơ quan hành chính dân sự
  • results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    07 biểu thị thực thể chính trị quốc gia và thường là loại thứ tự cao nhất được trả về bởi Bộ mã hóa địa lý
  • results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    08 chỉ ra một thực thể dân sự cấp một dưới cấp quốc gia. Trong phạm vi Hoa Kỳ, các cấp hành chính này là các bang. Không phải tất cả các quốc gia thể hiện các cấp hành chính. Trong hầu hết các trường hợp, các tên viết tắt cấp_khu vực_quản trị sẽ khớp chặt chẽ với các phân mục theo tiêu chuẩn ISO 3166-2 và các danh sách được lưu hành rộng rãi khác;
  • results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    09 chỉ ra một thực thể dân sự cấp hai dưới cấp quốc gia. Tại Hoa Kỳ, các cấp hành chính này là các hạt. Không phải tất cả các quốc gia thể hiện các cấp hành chính
  • results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    90 chỉ ra một thực thể dân sự bậc ba dưới cấp quốc gia. Loại này chỉ ra một bộ phận dân sự nhỏ. Không phải tất cả các quốc gia thể hiện các cấp hành chính
  • results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    91 chỉ ra một thực thể dân sự cấp bốn dưới cấp quốc gia. Loại này chỉ ra một bộ phận dân sự nhỏ. Không phải tất cả các quốc gia thể hiện các cấp hành chính
  • results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    92 chỉ ra một thực thể dân sự bậc năm dưới cấp quốc gia. Loại này chỉ ra một bộ phận dân sự nhỏ. Không phải tất cả các quốc gia thể hiện các cấp hành chính
  • results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    93 chỉ ra một thực thể dân sự bậc sáu dưới cấp quốc gia. Loại này chỉ ra một bộ phận dân sự nhỏ. Không phải tất cả các quốc gia thể hiện các cấp hành chính
  • results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    94 chỉ ra một thực thể dân sự bậc bảy dưới cấp quốc gia. Loại này chỉ ra một bộ phận dân sự nhỏ. Không phải tất cả các quốc gia thể hiện các cấp hành chính
  • results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    95 chỉ ra một tên thay thế thường được sử dụng cho thực thể
  • results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    02 chỉ ra một thực thể chính trị thành phố hoặc thị trấn hợp nhất
  • results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    97 chỉ ra một thực thể dân sự cấp một bên dưới một địa phương. Đối với một số địa điểm có thể nhận được một trong các loại bổ sung.
    results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    98 đến
    results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    99. Mỗi cấp địa phương là một thực thể dân sự. Số lớn hơn cho thấy một khu vực địa lý nhỏ hơn
  • results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    90 chỉ ra một vùng lân cận được đặt tên
  • results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    91 cho biết một vị trí được đặt tên, thường là một tòa nhà hoặc tập hợp các tòa nhà có tên chung
  • results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    92 biểu thị một thực thể cấp một bên dưới một vị trí được đặt tên, thường là một tòa nhà đơn lẻ trong một tập hợp các tòa nhà có tên chung
  • results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    93 cho biết tham chiếu vị trí được mã hóa, xuất phát từ vĩ độ và kinh độ. Mã cộng có thể được sử dụng để thay thế cho địa chỉ đường phố ở những nơi không tồn tại [nơi các tòa nhà không được đánh số hoặc đường phố không được đặt tên]. Xem https. //thêm. mã để biết chi tiết
  • results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    94 cho biết mã bưu chính được sử dụng để giải quyết thư bưu điện trong nước
  • results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    95 chỉ ra một đặc điểm tự nhiên nổi bật
  • results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    96 chỉ ra một sân bay
  • results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    97 chỉ ra một công viên được đặt tên
  • results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    98 chỉ ra một điểm ưa thích được đặt tên. Thông thường, những "POI" này là các thực thể địa phương nổi bật không dễ dàng phù hợp với danh mục khác, chẳng hạn như "Tòa nhà Empire State" hoặc "Tháp Eiffel"

Danh sách các loại trống cho biết không có loại nào được biết đến cho thành phần địa chỉ cụ thể, ví dụ: Lieu-dit ở Pháp

Ngoài những điều trên, các thành phần địa chỉ có thể bao gồm các loại bên dưới

Ghi chú. Danh sách này không đầy đủ và có thể thay đổi

  • results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    99 cho biết tầng của địa chỉ tòa nhà
  • results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    90 thường chỉ ra một địa điểm chưa được phân loại
  • results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    91 chỉ ra một địa điểm gần đó được sử dụng làm tài liệu tham khảo, để hỗ trợ điều hướng
  • results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    98 chỉ ra một điểm ưa thích được đặt tên
  • results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    93 cho biết bãi đậu xe hoặc cấu trúc bãi đậu xe
  • results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    94 chỉ ra một hộp thư cụ thể
  • results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    95 biểu thị một nhóm các khu vực địa lý, chẳng hạn như
    results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    02 và
    results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    97, được sử dụng cho địa chỉ gửi thư ở một số quốc gia
  • results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    98 cho biết phòng của địa chỉ tòa nhà
  • results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    99 cho biết số đường phố chính xác
  • results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    00,
    results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    01 và
    results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    02 cho biết vị trí của một điểm dừng xe buýt, xe lửa hoặc phương tiện công cộng

Mã trạng thái

  var geocoder;
  var map;
  function initialize[] {
    geocoder = new google.maps.Geocoder[];
    var latlng = new google.maps.LatLng[-34.397, 150.644];
    var mapOptions = {
      zoom: 8,
      center: latlng
    }
    map = new google.maps.Map[document.getElementById['map'], mapOptions];
  }

  function codeAddress[] {
    var address = document.getElementById['address'].value;
    geocoder.geocode[ { 'address': address}, function[results, status] {
      if [status == 'OK'] {
        map.setCenter[results[0].geometry.location];
        var marker = new google.maps.Marker[{
            map: map,
            position: results[0].geometry.location
        }];
      } else {
        alert['Geocode was not successful for the following reason: ' + status];
      }
    }];
  }


 
9 có thể trả về một trong các giá trị sau

  • results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    04 chỉ ra rằng không có lỗi xảy ra;
  • results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    05 cho biết rằng mã địa lý đã thành công nhưng không trả về kết quả nào. Điều này có thể xảy ra nếu bộ mã hóa địa lý được thông qua một
    results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    7 không tồn tại
  • results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    07 chỉ ra rằng bạn đã vượt quá hạn ngạch của mình
  • results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    08 chỉ ra rằng yêu cầu của bạn đã bị từ chối. Trang web không được phép sử dụng trình mã hóa địa lý
  • results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    09 thường chỉ ra rằng truy vấn [
    results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    7,
    results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    11 hoặc
    results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    12] bị thiếu
  • results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    13 cho biết không thể xử lý yêu cầu do lỗi máy chủ. Yêu cầu có thể thành công nếu bạn thử lại
  • results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    14 cho biết rằng yêu cầu đã hết thời gian chờ hoặc đã xảy ra sự cố khi kết nối với máy chủ Google. Yêu cầu có thể thành công nếu bạn thử lại

Trong ví dụ này, chúng tôi mã hóa địa lý một địa chỉ và đặt điểm đánh dấu ở các giá trị kinh độ và vĩ độ được trả về. Lưu ý rằng trình xử lý được chuyển dưới dạng hàm ẩn danh theo nghĩa đen

________số 8

Xem ví dụ

Xu hướng khung nhìn

Bạn có thể hướng dẫn Dịch vụ mã hóa địa lý ưu tiên kết quả trong một chế độ xem nhất định [được biểu thị dưới dạng hộp giới hạn]. Bạn làm như vậy bằng cách đặt tham số

  var geocoder;
  var map;
  function initialize[] {
    geocoder = new google.maps.Geocoder[];
    var latlng = new google.maps.LatLng[-34.397, 150.644];
    var mapOptions = {
      zoom: 8,
      center: latlng
    }
    map = new google.maps.Map[document.getElementById['map'], mapOptions];
  }

  function codeAddress[] {
    var address = document.getElementById['address'].value;
    geocoder.geocode[ { 'address': address}, function[results, status] {
      if [status == 'OK'] {
        map.setCenter[results[0].geometry.location];
        var marker = new google.maps.Marker[{
            map: map,
            position: results[0].geometry.location
        }];
      } else {
        alert['Geocode was not successful for the following reason: ' + status];
      }
    }];
  }


 
2 trong đối tượng
results[]: {
 types[]: string,
 formatted_address: string,
 address_components[]: {
   short_name: string,
   long_name: string,
   postcode_localities[]: string,
   types[]: string
 },
 partial_match: boolean,
 place_id: string,
 postcode_localities[]: string,
 geometry: {
   location: LatLng,
   location_type: GeocoderLocationType
   viewport: LatLngBounds,
   bounds: LatLngBounds
 }
}
5 bằng chữ để xác định giới hạn của chế độ xem này. Lưu ý rằng xu hướng chỉ thích kết quả trong giới hạn;

Ví dụ: mã địa lý cho "Winnetka" thường trả về vùng ngoại ô này của Chicago

results[]: {
 types[]: string,
 formatted_address: string,
 address_components[]: {
   short_name: string,
   long_name: string,
   postcode_localities[]: string,
   types[]: string
 },
 partial_match: boolean,
 place_id: string,
 postcode_localities[]: string,
 geometry: {
   location: LatLng,
   location_type: GeocoderLocationType
   viewport: LatLngBounds,
   bounds: LatLngBounds
 }
}
8

Tuy nhiên, việc chỉ định tham số

  var geocoder;
  var map;
  function initialize[] {
    geocoder = new google.maps.Geocoder[];
    var latlng = new google.maps.LatLng[-34.397, 150.644];
    var mapOptions = {
      zoom: 8,
      center: latlng
    }
    map = new google.maps.Map[document.getElementById['map'], mapOptions];
  }

  function codeAddress[] {
    var address = document.getElementById['address'].value;
    geocoder.geocode[ { 'address': address}, function[results, status] {
      if [status == 'OK'] {
        map.setCenter[results[0].geometry.location];
        var marker = new google.maps.Marker[{
            map: map,
            position: results[0].geometry.location
        }];
      } else {
        alert['Geocode was not successful for the following reason: ' + status];
      }
    }];
  }


 
2 xác định hộp giới hạn cho Thung lũng San Fernando của Los Angeles dẫn đến mã địa lý này trả về vùng lân cận có tên "Winnetka" ở vị trí đó

results[]: {
 types[]: string,
 formatted_address: string,
 address_components[]: {
   short_name: string,
   long_name: string,
   postcode_localities[]: string,
   types[]: string
 },
 partial_match: boolean,
 place_id: string,
 postcode_localities[]: string,
 geometry: {
   location: LatLng,
   location_type: GeocoderLocationType
   viewport: LatLngBounds,
   bounds: LatLngBounds
 }
}
1

Xu hướng mã vùng

Bạn có thể đặt Dịch vụ mã hóa địa lý để trả về kết quả thiên về một khu vực cụ thể một cách rõ ràng bằng cách sử dụng tham số

  var geocoder;
  var map;
  function initialize[] {
    geocoder = new google.maps.Geocoder[];
    var latlng = new google.maps.LatLng[-34.397, 150.644];
    var mapOptions = {
      zoom: 8,
      center: latlng
    }
    map = new google.maps.Map[document.getElementById['map'], mapOptions];
  }

  function codeAddress[] {
    var address = document.getElementById['address'].value;
    geocoder.geocode[ { 'address': address}, function[results, status] {
      if [status == 'OK'] {
        map.setCenter[results[0].geometry.location];
        var marker = new google.maps.Marker[{
            map: map,
            position: results[0].geometry.location
        }];
      } else {
        alert['Geocode was not successful for the following reason: ' + status];
      }
    }];
  }


 
6. Tham số này nhận mã vùng, được chỉ định dưới dạng thẻ phụ vùng Unicode gồm hai ký tự [không phải số]. Các thẻ này ánh xạ trực tiếp tới các giá trị hai ký tự ccTLD ["miền cấp cao nhất"] quen thuộc, chẳng hạn như "uk" trong "co. Anh" chẳng hạn. Trong một số trường hợp, thẻ
  var geocoder;
  var map;
  function initialize[] {
    geocoder = new google.maps.Geocoder[];
    var latlng = new google.maps.LatLng[-34.397, 150.644];
    var mapOptions = {
      zoom: 8,
      center: latlng
    }
    map = new google.maps.Map[document.getElementById['map'], mapOptions];
  }

  function codeAddress[] {
    var address = document.getElementById['address'].value;
    geocoder.geocode[ { 'address': address}, function[results, status] {
      if [status == 'OK'] {
        map.setCenter[results[0].geometry.location];
        var marker = new google.maps.Marker[{
            map: map,
            position: results[0].geometry.location
        }];
      } else {
        alert['Geocode was not successful for the following reason: ' + status];
      }
    }];
  }


 
6 cũng hỗ trợ mã ISO-3166-1, mã này đôi khi khác với giá trị ccTLD [ví dụ: "GB" cho "Great Britain"]

Khi sử dụng tham số

  var geocoder;
  var map;
  function initialize[] {
    geocoder = new google.maps.Geocoder[];
    var latlng = new google.maps.LatLng[-34.397, 150.644];
    var mapOptions = {
      zoom: 8,
      center: latlng
    }
    map = new google.maps.Map[document.getElementById['map'], mapOptions];
  }

  function codeAddress[] {
    var address = document.getElementById['address'].value;
    geocoder.geocode[ { 'address': address}, function[results, status] {
      if [status == 'OK'] {
        map.setCenter[results[0].geometry.location];
        var marker = new google.maps.Marker[{
            map: map,
            position: results[0].geometry.location
        }];
      } else {
        alert['Geocode was not successful for the following reason: ' + status];
      }
    }];
  }


 
6

  • Chỉ xác định một quốc gia hoặc khu vực. Nhiều giá trị bị bỏ qua và có thể dẫn đến yêu cầu không thành công
  • Chỉ sử dụng thẻ phụ vùng gồm hai ký tự [định dạng Unicode CLDR]. Tất cả các đầu vào khác sẽ dẫn đến lỗi
  • Chỉ các quốc gia và khu vực được liệt kê trong Chi tiết phạm vi nền tảng Google Maps mới được hỗ trợ

Yêu cầu mã hóa địa lý có thể được gửi cho mọi miền trong đó ứng dụng Google Maps chính cung cấp mã hóa địa lý. Lưu ý rằng xu hướng chỉ thích kết quả cho một miền cụ thể;

Ví dụ: mã địa lý cho "Toledo" trả về kết quả này vì miền mặc định cho Dịch vụ mã hóa địa lý được đặt thành Hoa Kỳ

results[]: {
 types[]: string,
 formatted_address: string,
 address_components[]: {
   short_name: string,
   long_name: string,
   postcode_localities[]: string,
   types[]: string
 },
 partial_match: boolean,
 place_id: string,
 postcode_localities[]: string,
 geometry: {
   location: LatLng,
   location_type: GeocoderLocationType
   viewport: LatLngBounds,
   bounds: LatLngBounds
 }
}
9

Mã địa lý cho "Toledo" với trường

  var geocoder;
  var map;
  function initialize[] {
    geocoder = new google.maps.Geocoder[];
    var latlng = new google.maps.LatLng[-34.397, 150.644];
    var mapOptions = {
      zoom: 8,
      center: latlng
    }
    map = new google.maps.Map[document.getElementById['map'], mapOptions];
  }

  function codeAddress[] {
    var address = document.getElementById['address'].value;
    geocoder.geocode[ { 'address': address}, function[results, status] {
      if [status == 'OK'] {
        map.setCenter[results[0].geometry.location];
        var marker = new google.maps.Marker[{
            map: map,
            position: results[0].geometry.location
        }];
      } else {
        alert['Geocode was not successful for the following reason: ' + status];
      }
    }];
  }


 
6 được đặt thành
results[]: {
 types[]: string,
 formatted_address: string,
 address_components[]: {
   short_name: string,
   long_name: string,
   postcode_localities[]: string,
   types[]: string
 },
 partial_match: boolean,
 place_id: string,
 postcode_localities[]: string,
 geometry: {
   location: LatLng,
   location_type: GeocoderLocationType
   viewport: LatLngBounds,
   bounds: LatLngBounds
 }
}
22 [Tây Ban Nha] sẽ trả về thành phố Tây Ban Nha

results[]: {
 types[]: string,
 formatted_address: string,
 address_components[]: {
   short_name: string,
   long_name: string,
   postcode_localities[]: string,
   types[]: string
 },
 partial_match: boolean,
 place_id: string,
 postcode_localities[]: string,
 geometry: {
   location: LatLng,
   location_type: GeocoderLocationType
   viewport: LatLngBounds,
   bounds: LatLngBounds
 }
}
0

Lọc thành phần

Bạn có thể đặt Dịch vụ mã hóa địa lý để trả về kết quả địa chỉ được giới hạn ở một khu vực cụ thể bằng cách sử dụng bộ lọc thành phần. Chỉ định bộ lọc trong tham số. Các giá trị bộ lọc hỗ trợ các phương pháp sửa chính tả và đối sánh một phần giống như các yêu cầu mã hóa địa lý khác

Trình mã hóa địa lý chỉ trả về các kết quả khớp với tất cả các bộ lọc thành phần. Nghĩa là, nó đánh giá các thông số kỹ thuật của bộ lọc là AND, không phải OR

Bộ lọc thành phần bao gồm một hoặc nhiều mục sau

  • results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    04 khớp với tên dài hoặc ngắn của tuyến đường
  • results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    02 trận đấu với các loại địa phương và tiểu địa phương
  • results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    26 phù hợp với tất cả các cấp của khu vực hành chính
  • results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    27 khớp với mã bưu chính và tiền tố mã bưu chính
  • results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    07 khớp với tên quốc gia hoặc mã quốc gia gồm hai chữ cái theo tiêu chuẩn ISO 3166-1. Ghi chú. API tuân theo tiêu chuẩn ISO để xác định quốc gia và bộ lọc hoạt động tốt nhất khi sử dụng mã ISO tương ứng của quốc gia

Ví dụ sau minh họa cách sử dụng tham số để lọc theo

results[]: {
 types[]: string,
 formatted_address: string,
 address_components[]: {
   short_name: string,
   long_name: string,
   postcode_localities[]: string,
   types[]: string
 },
 partial_match: boolean,
 place_id: string,
 postcode_localities[]: string,
 geometry: {
   location: LatLng,
   location_type: GeocoderLocationType
   viewport: LatLngBounds,
   bounds: LatLngBounds
 }
}
07 và
results[]: {
 types[]: string,
 formatted_address: string,
 address_components[]: {
   short_name: string,
   long_name: string,
   postcode_localities[]: string,
   types[]: string
 },
 partial_match: boolean,
 place_id: string,
 postcode_localities[]: string,
 geometry: {
   location: LatLng,
   location_type: GeocoderLocationType
   viewport: LatLngBounds,
   bounds: LatLngBounds
 }
}
27

results[]: {
 types[]: string,
 formatted_address: string,
 address_components[]: {
   short_name: string,
   long_name: string,
   postcode_localities[]: string,
   types[]: string
 },
 partial_match: boolean,
 place_id: string,
 postcode_localities[]: string,
 geometry: {
   location: LatLng,
   location_type: GeocoderLocationType
   viewport: LatLngBounds,
   bounds: LatLngBounds
 }
}
9

Mã hóa địa lý ngược [Tra cứu địa chỉ]

Thuật ngữ mã hóa địa lý thường đề cập đến việc dịch một địa chỉ mà con người có thể đọc được thành một vị trí trên bản đồ. Quá trình thực hiện ngược lại, dịch một vị trí trên bản đồ thành địa chỉ mà con người có thể đọc được, được gọi là mã hóa địa lý ngược

Thay vì cung cấp một văn bản

results[]: {
 types[]: string,
 formatted_address: string,
 address_components[]: {
   short_name: string,
   long_name: string,
   postcode_localities[]: string,
   types[]: string
 },
 partial_match: boolean,
 place_id: string,
 postcode_localities[]: string,
 geometry: {
   location: LatLng,
   location_type: GeocoderLocationType
   viewport: LatLngBounds,
   bounds: LatLngBounds
 }
}
7, hãy cung cấp một cặp kinh độ/vĩ độ được phân tách bằng dấu phẩy trong tham số
results[]: {
 types[]: string,
 formatted_address: string,
 address_components[]: {
   short_name: string,
   long_name: string,
   postcode_localities[]: string,
   types[]: string
 },
 partial_match: boolean,
 place_id: string,
 postcode_localities[]: string,
 geometry: {
   location: LatLng,
   location_type: GeocoderLocationType
   viewport: LatLngBounds,
   bounds: LatLngBounds
 }
}
8

Ghi chú. Nếu bạn bao gồm tham số
  var geocoder;
  var map;
  function initialize[] {
    geocoder = new google.maps.Geocoder[];
    var latlng = new google.maps.LatLng[-34.397, 150.644];
    var mapOptions = {
      zoom: 8,
      center: latlng
    }
    map = new google.maps.Map[document.getElementById['map'], mapOptions];
  }

  function codeAddress[] {
    var address = document.getElementById['address'].value;
    geocoder.geocode[ { 'address': address}, function[results, status] {
      if [status == 'OK'] {
        map.setCenter[results[0].geometry.location];
        var marker = new google.maps.Marker[{
            map: map,
            position: results[0].geometry.location
        }];
      } else {
        alert['Geocode was not successful for the following reason: ' + status];
      }
    }];
  }


 
5 trong yêu cầu thì tham số
results[]: {
 types[]: string,
 formatted_address: string,
 address_components[]: {
   short_name: string,
   long_name: string,
   postcode_localities[]: string,
   types[]: string
 },
 partial_match: boolean,
 place_id: string,
 postcode_localities[]: string,
 geometry: {
   location: LatLng,
   location_type: GeocoderLocationType
   viewport: LatLngBounds,
   bounds: LatLngBounds
 }
}
8 sẽ bị bỏ qua

Ví dụ sau mã hóa địa lý một giá trị kinh độ/vĩ độ và căn giữa bản đồ tại vị trí đó, hiển thị cửa sổ thông tin với địa chỉ được định dạng

bản đánh máy

results[]: {
 types[]: string,
 formatted_address: string,
 address_components[]: {
   short_name: string,
   long_name: string,
   postcode_localities[]: string,
   types[]: string
 },
 partial_match: boolean,
 place_id: string,
 postcode_localities[]: string,
 geometry: {
   location: LatLng,
   location_type: GeocoderLocationType
   viewport: LatLngBounds,
   bounds: LatLngBounds
 }
}
9Ghi chú. Đọc hướng dẫn sử dụng TypeScript và Google Maps

JavaScript

results[]: {
 types[]: string,
 formatted_address: string,
 address_components[]: {
   short_name: string,
   long_name: string,
   postcode_localities[]: string,
   types[]: string
 },
 partial_match: boolean,
 place_id: string,
 postcode_localities[]: string,
 geometry: {
   location: LatLng,
   location_type: GeocoderLocationType
   viewport: LatLngBounds,
   bounds: LatLngBounds
 }
}
9Ghi chú. JavaScript được biên dịch từ đoạn mã TypeScript

Xem ví dụ

thử mẫu

Stackblitz. com Mã Sandbox. io JSFiddle. mạng Google Cloud Shell

Lưu ý rằng trong ví dụ trước, chúng tôi đã hiển thị kết quả đầu tiên bằng cách chọn

results[]: {
 types[]: string,
 formatted_address: string,
 address_components[]: {
   short_name: string,
   long_name: string,
   postcode_localities[]: string,
   types[]: string
 },
 partial_match: boolean,
 place_id: string,
 postcode_localities[]: string,
 geometry: {
   location: LatLng,
   location_type: GeocoderLocationType
   viewport: LatLngBounds,
   bounds: LatLngBounds
 }
}
36. Trình mã hóa địa lý đảo ngược thường trả về nhiều hơn một kết quả. Địa chỉ được mã hóa địa lý không chỉ là địa chỉ bưu chính, mà là bất kỳ cách nào để đặt tên địa lý cho một vị trí. Ví dụ: khi mã hóa địa lý một điểm trong thành phố Chicago, điểm được mã hóa địa lý có thể được gắn nhãn là địa chỉ đường phố, thành phố [Chicago], tiểu bang của nó [Illinois] hoặc quốc gia [Hoa Kỳ]. Tất cả đều là địa chỉ cho bộ mã hóa địa lý. Trình mã hóa địa lý ngược trả về tất cả các kết quả này

Trình mã hóa địa lý ngược khớp với các thực thể chính trị [quốc gia, tỉnh, thành phố và vùng lân cận], địa chỉ đường phố và mã bưu điện

Đây là một ví dụ về danh sách các địa chỉ mà truy vấn trên có thể trả về

results[]: {
 types[]: string,
 formatted_address: string,
 address_components[]: {
   short_name: string,
   long_name: string,
   postcode_localities[]: string,
   types[]: string
 },
 partial_match: boolean,
 place_id: string,
 postcode_localities[]: string,
 geometry: {
   location: LatLng,
   location_type: GeocoderLocationType
   viewport: LatLngBounds,
   bounds: LatLngBounds
 }
}
0

Địa chỉ được trả về theo thứ tự phù hợp nhất đến ít nhất. Nói chung, địa chỉ chính xác hơn là kết quả nổi bật nhất, như trong trường hợp này. Lưu ý rằng chúng tôi trả về các loại địa chỉ khác nhau, từ địa chỉ đường phố cụ thể nhất đến các thực thể chính trị ít cụ thể hơn như vùng lân cận, thành phố, hạt, tiểu bang, v.v. Nếu bạn muốn khớp một địa chỉ tổng quát hơn, bạn có thể muốn kiểm tra trường

results[]: {
 types[]: string,
 formatted_address: string,
 address_components[]: {
   short_name: string,
   long_name: string,
   postcode_localities[]: string,
   types[]: string
 },
 partial_match: boolean,
 place_id: string,
 postcode_localities[]: string,
 geometry: {
   location: LatLng,
   location_type: GeocoderLocationType
   viewport: LatLngBounds,
   bounds: LatLngBounds
 }
}
37

Ghi chú. Mã hóa địa lý ngược không phải là một khoa học chính xác. Trình mã hóa địa lý sẽ cố gắng tìm vị trí có thể định địa chỉ gần nhất trong một dung sai nhất định

Truy xuất Địa chỉ cho ID Địa điểm

Cung cấp một

  var geocoder;
  var map;
  function initialize[] {
    geocoder = new google.maps.Geocoder[];
    var latlng = new google.maps.LatLng[-34.397, 150.644];
    var mapOptions = {
      zoom: 8,
      center: latlng
    }
    map = new google.maps.Map[document.getElementById['map'], mapOptions];
  }

  function codeAddress[] {
    var address = document.getElementById['address'].value;
    geocoder.geocode[ { 'address': address}, function[results, status] {
      if [status == 'OK'] {
        map.setCenter[results[0].geometry.location];
        var marker = new google.maps.Marker[{
            map: map,
            position: results[0].geometry.location
        }];
      } else {
        alert['Geocode was not successful for the following reason: ' + status];
      }
    }];
  }


 
1 để tìm địa chỉ cho một ID địa điểm nhất định. ID địa điểm là một mã định danh duy nhất có thể được sử dụng với các API Google khác. Ví dụ: bạn có thể cung cấp
  var geocoder;
  var map;
  function initialize[] {
    geocoder = new google.maps.Geocoder[];
    var latlng = new google.maps.LatLng[-34.397, 150.644];
    var mapOptions = {
      zoom: 8,
      center: latlng
    }
    map = new google.maps.Map[document.getElementById['map'], mapOptions];
  }

  function codeAddress[] {
    var address = document.getElementById['address'].value;
    geocoder.geocode[ { 'address': address}, function[results, status] {
      if [status == 'OK'] {
        map.setCenter[results[0].geometry.location];
        var marker = new google.maps.Marker[{
            map: map,
            position: results[0].geometry.location
        }];
      } else {
        alert['Geocode was not successful for the following reason: ' + status];
      }
    }];
  }


 
1 do API Đường bộ trả về để lấy địa chỉ cho một điểm bị gãy. Để biết thêm thông tin về ID địa điểm, hãy xem tổng quan về ID địa điểm

Khi bạn cung cấp

  var geocoder;
  var map;
  function initialize[] {
    geocoder = new google.maps.Geocoder[];
    var latlng = new google.maps.LatLng[-34.397, 150.644];
    var mapOptions = {
      zoom: 8,
      center: latlng
    }
    map = new google.maps.Map[document.getElementById['map'], mapOptions];
  }

  function codeAddress[] {
    var address = document.getElementById['address'].value;
    geocoder.geocode[ { 'address': address}, function[results, status] {
      if [status == 'OK'] {
        map.setCenter[results[0].geometry.location];
        var marker = new google.maps.Marker[{
            map: map,
            position: results[0].geometry.location
        }];
      } else {
        alert['Geocode was not successful for the following reason: ' + status];
      }
    }];
  }


 
1, yêu cầu không được chứa bất kỳ trường nào sau đây

  • results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    7
  • results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    42
  • results[]: {
     types[]: string,
     formatted_address: string,
     address_components[]: {
       short_name: string,
       long_name: string,
       postcode_localities[]: string,
       types[]: string
     },
     partial_match: boolean,
     place_id: string,
     postcode_localities[]: string,
     geometry: {
       location: LatLng,
       location_type: GeocoderLocationType
       viewport: LatLngBounds,
       bounds: LatLngBounds
     }
    }
    
    8
  •   var geocoder;
      var map;
      function initialize[] {
        geocoder = new google.maps.Geocoder[];
        var latlng = new google.maps.LatLng[-34.397, 150.644];
        var mapOptions = {
          zoom: 8,
          center: latlng
        }
        map = new google.maps.Map[document.getElementById['map'], mapOptions];
      }
    
      function codeAddress[] {
        var address = document.getElementById['address'].value;
        geocoder.geocode[ { 'address': address}, function[results, status] {
          if [status == 'OK'] {
            map.setCenter[results[0].geometry.location];
            var marker = new google.maps.Marker[{
                map: map,
                position: results[0].geometry.location
            }];
          } else {
            alert['Geocode was not successful for the following reason: ' + status];
          }
        }];
      }
    
    
     
    5

Ví dụ sau chấp nhận ID địa điểm, tìm địa chỉ tương ứng và căn giữa bản đồ tại vị trí đó. Nó cũng hiển thị một cửa sổ thông tin hiển thị địa chỉ được định dạng của địa điểm có liên quan

Làm cách nào để có được vị trí bản đồ Google trong php?

Hãy bắt đầu thêm Google Map bằng PHP .
Nhận khóa API Google Map
Chúng tôi sẽ tạo một div sẽ hiển thị bản đồ
Chúng tôi sẽ tạo trình bao bọc API trong PHP sẽ nhận địa chỉ, vĩ độ và kinh độ được định dạng bằng tên Thành phố

Làm cách nào để lấy địa chỉ vị trí hiện tại trong php?

Phương thức getCurrentPosition[] được sử dụng để lấy vị trí của khách truy cập và phương thức showLocation[] được sử dụng để lấy địa chỉ của khách truy cập từ getLocation. tệp php sử dụng Ajax. Mã HTML . Sau khi nhận được vị trí của khách truy cập, địa chỉ sẽ được hiển thị trên trang web [ #location span].

Chủ Đề