Javascript 在谷歌地图上显示标记
我构建了一个脚本,用于初始化特定点的贴图: 注:Javascript 在谷歌地图上显示标记,javascript,jquery,google-maps,google-maps-api-3,Javascript,Jquery,Google Maps,Google Maps Api 3,我构建了一个脚本,用于初始化特定点的贴图: 注:(x,y)是经纬度坐标 <script type="text/javascript"> var businessMap; function showBusinessMap(x, y) { var xops = { zoom: 15, center: new google.maps.LatLn
(x,y)
是经纬度坐标
<script type="text/javascript">
var businessMap;
function showBusinessMap(x, y) {
var xops =
{
zoom: 15,
center: new google.maps.LatLng(x, y)
}
var chosenPoint = new google.maps.Marker({
position: new google.maps.LatLng(x, y),
});
businessMap = new google.maps.Map(document.getElementById("businessMap"), xops);
chosenPoint.setMap(businessMap);
chosenPoint.setVisible(true);
}
</script>
如何使标记chosenPoint
显示
如果我错过了任何信息,请让我知道,我会添加它
提前谢谢
编辑:
仍然不起作用。编辑:
您需要将创建的chosenPoint
添加到地图中
从谷歌地图API
var myLatlng = new google.maps.LatLng(-25.363882,131.044922);
var mapOptions = {
zoom: 4,
center: myLatlng
}
var map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
// To add the marker to the map, use the 'map' property
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title:"Hello World!"
});
因此,在您的例子中,首先创建map对象,然后创建marker对象,并在marker的选项中包括map:businessMap
,就像上面的示例一样
以下部分是添加“标记”的部分
作为一个起点,这里有一个基于您的代码的简单示例。我想你的问题是由你给我们看的以外的东西引起的
<script type="text/javascript">
var businessMap;
function showBusinessMap(x, y) {
var xops = {
zoom: 15,
center: new google.maps.LatLng(x, y)
};
var businessMap = new google.maps.Map(document.getElementById("businessMap"),
xops);
var chosenPoint = new google.maps.Marker({
position: new google.maps.LatLng(x, y),
map: businessMap
});
}
function initialize() {
showBusinessMap(-34.397, 150.644);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
var商业地图;
功能showBusinessMap(x,y){
var xops={
缩放:15,
中心:新google.maps.LatLng(x,y)
};
var businessMap=new google.maps.Map(document.getElementById(“businessMap”),
xops);
var chosenPoint=new google.maps.Marker({
位置:新google.maps.LatLng(x,y),
地图:商业地图
});
}
函数初始化(){
showBusinessMap(-34.397150.644);
}
google.maps.event.addDomListener(窗口“加载”,初始化);
定义“不起作用”。我怀疑它工作得很好,而且您的map div没有大小(至少它在本地副本上对我有效)。
var myLatlng = new google.maps.LatLng(-25.363882,131.044922);
var mapOptions = {
zoom: 4,
center: myLatlng
}
var map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
// To add the marker to the map, use the 'map' property
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title:"Hello World!"
});
var address = "Address, City, ProvinceOrState, Country";
geocoder.geocode({ 'address': address }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
//console.log("GeocoderStatus.OK : " + results[0].geometry.location);
var mapOptions = {
zoom: 8,
center: results[0].geometry.location,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
//load the map
map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
} //if
else { console.log("Geocode was not successful for the following reason: " + status); }
})
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
<script type="text/javascript">
var businessMap;
function showBusinessMap(x, y) {
var xops = {
zoom: 15,
center: new google.maps.LatLng(x, y)
};
var businessMap = new google.maps.Map(document.getElementById("businessMap"),
xops);
var chosenPoint = new google.maps.Marker({
position: new google.maps.LatLng(x, y),
map: businessMap
});
}
function initialize() {
showBusinessMap(-34.397, 150.644);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>