我正在尝试使用google api检索我的地理位置的lat。这个api接受了蜂窝塔信息。无论提供所有信息,我都没有得到正确的lat。
https://developers.google.com/maps/documentation/geolocation/intro
是否有人使用此API查找lat long?人们应该从Google的Geo位置API获得多少精确度?
答案 0 :(得分:0)
下面我已将此sample from google扩展为读取Lat / Lng:
JavaScript代码
function initAutocomplete() {
// Create the autocomplete object, restricting the search to geographical
// location types.
autocomplete = new google.maps.places.Autocomplete(
/** @type {!HTMLInputElement} */(document.getElementById('autocomplete')),
{types: ['geocode']});
// When the user selects an address from the dropdown, populate the address
// fields in the form.
autocomplete.addListener('place_changed', fillInAddress);
}
function fillInAddress() {
// Get the place details from the autocomplete object.
var place = autocomplete.getPlace();
// get latitude and longitude
// --------------------------
var lat = place.geometry.location.lat();
var lng = place.geometry.location.lng();
// other stuff...
}
您的HTML地址字段
<input id="autocomplete" placeholder="Enter your address"
onFocus="geolocate()" type="text"></input>