Javascript 标记点谷歌地图自定义脚本
我的网页中有我的自定义地图脚本,但它没有用于精确定位的点标记:Javascript 标记点谷歌地图自定义脚本,javascript,c#,google-maps,google-maps-markers,Javascript,C#,Google Maps,Google Maps Markers,我的网页中有我的自定义地图脚本,但它没有用于精确定位的点标记: <script> /* Map */ (function () { "use strict"; if (document.getElementById("map")) { var locations = [ ['<div class="map-info-box"><ul class="contact-info-list"><li>
<script>
/* Map */
(function () {
"use strict";
if (document.getElementById("map")) {
var locations = [
['<div class="map-info-box"><ul class="contact-info-list"><li><span><i class="fa fa-home fa-fw"></i></span> Mimar Sinan Mh., Konak/İzmir, Türkiye</li><li><span><i class="fa fa-phone fa-fw"></i></span> +90 0 (232) 324 11 83</li></ul></div>', 38.396652, 27.090560, 9]
];
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 13,
center: new google.maps.LatLng(29.0961599, -110.96087460000001),
scrollwheel: false,
mapTypeId: google.maps.MapTypeId.ROADMAP,
styles: [{ "featureType": "all", "elementType": "all", "stylers": [{ "saturation": -100 }, { "gamma": 0.5 }] }]
});
var infowindow = new google.maps.InfoWindow();
var marker, i;
for (i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
map: map,
animation: google.maps.Animation.DROP,
icon: 'images/pin.png',
});
google.maps.event.addListener(marker, 'click', (function (marker, i) {
return function () {
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
}
})(marker, i));
}
}
}());
/*地图*/
(功能(){
“严格使用”;
if(document.getElementById(“map”)){
变量位置=[
[ul class=“联系人信息列表”>Mimar Sinan Mh.,Konak/İzmir,Türkiye +90 0(232)324 11 83,38.396652,27.090560,9]
];
var map=new google.maps.map(document.getElementById('map'){
缩放:13,
中心:新google.maps.LatLng(29.0961599,-110.96087460000001),
滚轮:错误,
mapTypeId:google.maps.mapTypeId.ROADMAP,
样式:[{“featureType”:“all”,“elementType”:“all”,“stylers”:[{“saturation”:-100},{“gamma”:0.5}]}]
});
var infowindow=new google.maps.infowindow();
var标记,i;
对于(i=0;i
因此,我需要添加类似默认嵌入贴图的标记点:
#gmap_画布img{最大宽度:无!重要;背景:无!重要}
函数init_map(){var myOptions={zoom:13,中间:new google.maps.LatLng(29.0961599,-110.96087460000001),
mapTypeId:google.maps.mapTypeId.ROADMAP};map=new google.maps.map(document.getElementById(“gmap_canvas”),myOptions;
marker=new google.maps.marker({map:map,position:new google.maps.LatLng(29.0961599,-110.96087460000001)});
infowindow=new google.maps.infowindow({content:“Minerals
Reyes#100
83190 Hermosillo});
google.maps.event.addListener(marker,“click”,function(){infowindow.open(map,marker);});
infowindow.open(地图、标记);}
google.maps.event.addDomListener(窗口'load',初始化映射);
如何确保我的标记显示为默认地图?
您的答案非常宝贵我认为您需要将标记声明放入initMap()函数中,以便在加载地图时在特定坐标处放置默认标记。这是谷歌官方文档中的HTML+Javascript代码
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Simple markers</title>
<style>
html, body {
height: 100%;
margin: 0;
padding: 0;
}
#map {
height: 100%;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
function initMap() {
var myLatLng = {lat: -25.363, lng: 131.044};
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 4,
center: myLatLng
});
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
title: 'Hello World!'
});
}
</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?signed_in=true&callback=initMap"></script>
</body>
</html>
简单标记
html,正文{
身高:100%;
保证金:0;
填充:0;
}
#地图{
身高:100%;
}
函数initMap(){
var Mylatng={lat:-25.363,液化天然气:131.044};
var map=new google.maps.map(document.getElementById('map'){
缩放:4,
中心:myLatLng
});
var marker=new google.maps.marker({
职位:myLatLng,
地图:地图,
标题:“你好,世界!”
});
}
有关更多详细信息,请参见 你需要像这样使用它,它对我有用 将此div添加到要显示地图的html页面上
<div class="google-map-canvas" id="map-canvas"></div>
再加上这个脚本
function initialize() {
// Change the latitude and longitude to your location. You can also get the coordinates here: http://itouchmap.com/latlong.html
var myLatlng = new google.maps.LatLng(25.548710, 82.084777);
var mapOptions = {
zoom: 17,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
var marker = new google.maps.Marker({
position: myLatlng,
map: map
});
var infowindow = new google.maps.InfoWindow({
content:
'<div class="map-wrap">' +
// Company name
'<div class="b-title">' + 'Company Name' + '</div>' +
// Company street
'<p>' + 'Company Street' + '</p>' +
// Company city and state
'<p>' + 'Company City and State' + '</p>' +
// Clearfix with border
'<div class="clrfx map-div">' + '</div>' +
// Row 1
'<div class="row">' +
// Phone
'<div class="b-info cell w-49">' + '<span class="entypo-phone">' + '</span>' + '+91-879-902-1616' + '</div>' +
// Email
'<div class="b-info cell w-49">' + '<span class="entypo-paper-plane">' + '</span>' + 'example@example.com' + '</div>' +
'</div>' +
// Row 2
'<div class="row">' +
// Mobile
'<div class="b-info cell w-49">' + '<span class="entypo-mobile">' + '</span>' + '+91-879-902-1616' + '</div>' +
// Website
'<div class="b-info cell w-49">' + '<span class="entypo-monitor">' + '</span>' + 'www.example.com' + '</div>' +
'</div>' +
// Bottom margin clearfix
'<div class="clrfx mt-10">' + '</div>' +
'</div>'
});
makeInfoWindowEvent(map, infowindow, marker);
}
function makeInfoWindowEvent(map, infowindow, marker) {
google.maps.event.addListener(marker, 'click', function () {
infowindow.open(map, marker);
});
}
google.maps.event.addDomListener(window, 'load', initialize);
函数初始化(){
//将纬度和经度更改为您的位置。您还可以在此处获取坐标:http://itouchmap.com/latlong.html
var mylatng=new google.maps.LatLng(25.548710,82.084777);
变量映射选项={
缩放:17,
中心:myLatlng,
mapTypeId:google.maps.mapTypeId.ROADMAP
}
var map=new google.maps.map(document.getElementById('map-canvas'),mapOptions);
var marker=new google.maps.marker({
职位:myLatlng,
地图:地图
});
var infowindow=new google.maps.infowindow({
内容:
'' +
//公司名称
“+”公司名称“+”+
//公司街
“”+“公司街”+“”+
//城市和州公司
“”+”公司城市和州“+””+
//带边框的Clearfix
'' + '' +
//第1行
'' +
//电话
'' + '' + '' + '+91-879-902-1616' + '' +
//电子邮件
'' + '' + '' + 'example@example.com' + '' +
'' +
//第2排
'' +
//流动的
'' + '' + '' + '+91-879-902-1616' + '' +
//网站
“+”+“+”+”www.example.com“+”+
'' +
//底边空白固定
'' + '' +
''
});
makeInfoWindowEvent(映射、信息窗口、标记);
}
函数makeInfoWindowEvent(映射、信息窗口、标记){
google.maps.event.addListener(标记,'click',函数(){
信息窗口。打开(地图、标记);
});
}
google.maps.event.addDomListener(窗口“加载”,初始化);
function initialize() {
// Change the latitude and longitude to your location. You can also get the coordinates here: http://itouchmap.com/latlong.html
var myLatlng = new google.maps.LatLng(25.548710, 82.084777);
var mapOptions = {
zoom: 17,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
var marker = new google.maps.Marker({
position: myLatlng,
map: map
});
var infowindow = new google.maps.InfoWindow({
content:
'<div class="map-wrap">' +
// Company name
'<div class="b-title">' + 'Company Name' + '</div>' +
// Company street
'<p>' + 'Company Street' + '</p>' +
// Company city and state
'<p>' + 'Company City and State' + '</p>' +
// Clearfix with border
'<div class="clrfx map-div">' + '</div>' +
// Row 1
'<div class="row">' +
// Phone
'<div class="b-info cell w-49">' + '<span class="entypo-phone">' + '</span>' + '+91-879-902-1616' + '</div>' +
// Email
'<div class="b-info cell w-49">' + '<span class="entypo-paper-plane">' + '</span>' + 'example@example.com' + '</div>' +
'</div>' +
// Row 2
'<div class="row">' +
// Mobile
'<div class="b-info cell w-49">' + '<span class="entypo-mobile">' + '</span>' + '+91-879-902-1616' + '</div>' +
// Website
'<div class="b-info cell w-49">' + '<span class="entypo-monitor">' + '</span>' + 'www.example.com' + '</div>' +
'</div>' +
// Bottom margin clearfix
'<div class="clrfx mt-10">' + '</div>' +
'</div>'
});
makeInfoWindowEvent(map, infowindow, marker);
}
function makeInfoWindowEvent(map, infowindow, marker) {
google.maps.event.addListener(marker, 'click', function () {
infowindow.open(map, marker);
});
}
google.maps.event.addDomListener(window, 'load', initialize);