sam*_*ami 3 google-maps google-maps-api-3
我必须将谷歌地图嵌入到网页上,但我不允许使用 iframe - 公司政策 - 还有其他方法吗?我检查了一些东西,比如 javascript 地图,但他们似乎也在使用 iframes https://developers.google.com/maps/documentation/javascript/tutorial,至少如果你检查萤火虫,地图在 iframe 中以及。是否有任何 API 或任何其他方法可以在没有 iframe 的情况下做到这一点?谢谢
在网页上使用 Google 地图有两种方法。iframe 和 API。在您的情况下,您可以使用 Google Map API V3 来呈现 Google Map,因为您不想使用 Iframe。使用 Google Map API 代替 Iframe 的另一个优点是,它比 Iframe 运行得更快。在这里阅读https://webmasters.stackexchange.com/questions/51444/google-maps-iframe-vs-api-which-is-faster-if-any
您可以使用下面的代码在我们的页面上有简单的地图
var map;
var geocoder;
var mapOptions = { center: new google.maps.LatLng(0.0, 0.0), zoom: 2,
mapTypeId: google.maps.MapTypeId.ROADMAP };
function initialize() {
var myOptions = {
center: new google.maps.LatLng(40.713955826286046, -73.992919921875 ),
zoom: 15,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
}
//This will render map on load
google.maps.event.addDomListener(window, 'load', initialize);
Run Code Online (Sandbox Code Playgroud)
html, body, #map_canvas { margin: 0; padding: 0; height: 100% }
Run Code Online (Sandbox Code Playgroud)
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<div id="map_canvas"></div>
Run Code Online (Sandbox Code Playgroud)
您可以在此处阅读有关 Google Map JavaScript API V3 的更多信息https://developers.google.com/maps/documentation/javascript/
希望这可以帮助!