如何在Google地图上显示所选地点。我尝试了很少的东西,但它没有用。
下面是我的代码,
var map;
function initMap(lat, lng)
{
lat = parseFloat(lat);
lng = parseFloat(lng);
map = new google.maps.Map(document.getElementById('map'), {
'center' : {'lat': parseFloat(lat), 'lng': parseFloat(lng)},
'zoom' : 15,
'disableDefaultUI': false,
'mapTypeId' : google.maps.MapTypeId.ROADMAP
});
var myCenter=new google.maps.LatLng(lat, lng);
var marker=new google.maps.Marker({
position:myCenter,
icon:'https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcShhM5Gh9yzCVdoX_vTshfbfRQxFkXWkysxyXo2GtrBySldFejs5w'
});
marker.setMap(map);
var request = {
location: { lat, lng},
radius: '50000',
types: ['hospital','bus_station','travel_agency','subway_station','taxi_stand','doctor','dentist','bus_station','airport']
};
service = new google.maps.places.PlacesService(map);
service.nearbySearch(request, callback);
}
function callback(results, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
for (var i = 0; i < results.length; i++) {
var place = results[i];
console.log(" Places ", place);
createMarker(results[i]);
}
}
}
function createMarker(place) {
var placeLoc = place.geometry.location;
var marker = new google.maps.Marker({
map: map,
position: place.geometry.location
});
marker.setMap(map);
}
在代码中我提到只显示地点类型
['hospital','bus_station','travel_agency','subway_station','taxi_stand','doctor','dentist','bus_station','airport']
但是它显示其他地方太像餐馆,酒店等等,你可以在附图中看到
如何禁用我想仅填充给定位置的其他地方?