function initAMap() { try { // 更新为完整地址 const address = '广东省深圳市南山区粤海街道麻岭社区麻雀岭工业区M-6栋中钢大厦5A010'; const companyName = '深圳汉晶电子信息有限公司'; // 创建地图实例 let map = null; // 地址解析 AMap.plugin('AMap.Geocoder', function() { const geocoder = new AMap.Geocoder({ city: "深圳", radius: 1000 }); geocoder.getLocation(address, function(status, result) { if (status === 'complete' && result.info === 'OK') { const lnglat = result.geocodes[0].location; map = new AMap.Map('mapContainer', { zoom: 16, center: [lnglat.lng, lnglat.lat], viewMode: '3D', resizeEnable: true, pitch: 40, mapStyle: 'amap://styles/normal' }); // 更新标记信息 const marker = new AMap.Marker({ position: [lnglat.lng, lnglat.lat], title: companyName, animation: 'AMAP_ANIMATION_DROP', offset: new AMap.Pixel(-13, -30) }); map.add(marker); // 更新信息窗体内容 const content = `

${companyName}

地址:${address}

电话:13420976989

Email:fu.bin@hjsilicon.com

`; // 创建信息窗体 const infoWindow = new AMap.InfoWindow({ content: content, offset: new AMap.Pixel(0, -30), closeWhenClickMap: true }); // 地图加载完成后打开信息窗体 map.on('complete', function() { infoWindow.open(map, [lnglat.lng, lnglat.lat]); }); // 点击标记时打开信息窗体 marker.on('click', function() { infoWindow.open(map, marker.getPosition()); }); // 添加控件 map.addControl(new AMap.ToolBar({ position: 'RB' })); map.addControl(new AMap.Scale()); // 确保标记点居中显示 map.setFitView([marker]); // 响应式处理 window.addEventListener('resize', function() { map.resize(); map.setCenter([lnglat.lng, lnglat.lat]); }); } else { console.error('地址解析失败:', result); document.getElementById('mapContainer').innerHTML = '
地址定位失败,请刷新重试
'; } }); }); } catch (error) { console.error('地图初始化失败:', error); document.getElementById('mapContainer').innerHTML = '
地图加载失败,请刷新重试
'; } } // DOM加载完成时初始化 document.addEventListener('DOMContentLoaded', function() { if (typeof AMap !== 'undefined') { initAMap(); } }); // 回调函数 window.initMap = function() { if (typeof AMap !== 'undefined') { initAMap(); } };