可以用地址解析器解析景点的地址得到经纬度,而不是从经纬度获取景点 geocoder = new google.maps.Geocoder();
geocoder.geocode({ 'address': '北京市朝阳区西大望路3号蓝堡国际中心' }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
console.log( results[0].geometry.location)/////////
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
geocoder.geocode({ 'address': '北京市朝阳区西大望路3号蓝堡国际中心' }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
console.log( results[0].geometry.location)/////////
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
window.onload = function() {
//初始化地图13.var map = new google.maps.Map(document.getElementById("map_canvas"),
{ center : new google.maps.LatLng(26.57, 106.72),
zoom : 8,
mapTypeId : google.maps.MapTypeId.ROADMAP,
});
//实例化Geocoder服务
var geocoder = new google.maps.Geocoder();//1.地理解析过程
//请求数据GeocoderRequest为address,值为'贵阳'
geocoder.geocode({address:'贵阳'},function geoResults(results, status){
//这里是回掉函数(即结果处理函数)
//状态为Ok说明有结果
if (status == google.maps.GeocoderStatus.OK) {
//一般情况下会有多个结果
//第一个结果为最佳匹配的结果(匹配地名最全的结果),这里只去第一个,其他的可以根据需要自己循环出来
//格式化过后的地址
alert('地理解析结果:'+results[0].formatted_address);
//geometry是一个包含bounds(界限),location(纬度/经度坐标),location_type和viewport(视图范围)
//获取解析后的经纬度
alert('地理解析结果:'+results[0].geometry.location);
}else{
alert(":error " + status);
}
});
window.onload = function() {
//初始化地图13.var map = new google.maps.Map(document.getElementById("map_canvas"),
{ center : new google.maps.LatLng(26.57, 106.72),
zoom : 8,
mapTypeId : google.maps.MapTypeId.ROADMAP,
});
//实例化Geocoder服务
var geocoder = new google.maps.Geocoder();//1.地理解析过程
//请求数据GeocoderRequest为address,值为'贵阳'
geocoder.geocode({address:'贵阳'},function geoResults(results, status){
//这里是回掉函数(即结果处理函数)
//状态为Ok说明有结果
if (status == google.maps.GeocoderStatus.OK) {
//一般情况下会有多个结果
//第一个结果为最佳匹配的结果(匹配地名最全的结果),这里只去第一个,其他的可以根据需要自己循环出来
//格式化过后的地址
alert('地理解析结果:'+results[0].formatted_address);
//geometry是一个包含bounds(界限),location(纬度/经度坐标),location_type和viewport(视图范围)
//获取解析后的经纬度
alert('地理解析结果:'+results[0].geometry.location);
}else{
alert(":error " + status);
}
});