简体   繁体   English

如何询问位置然后用谷歌地图显示

[英]how to ask for location then display with google maps

I want to write a program that will ask the users location using modernizer and display it using google maps.我想编写一个程序,该程序将使用 Modernizer 询问用户位置并使用谷歌地图显示它。 The most I could get up to was using geolocation to find your location coordinates, and trying to use the google maps api to get a map on my page.我最多只能使用地理定位来查找您的位置坐标,并尝试使用谷歌地图 API 在我的页面上获取地图。 jsfiddle.net/DavDaBomb21/279fbf8b/ jsfiddle.net/DavDaBomb21/279fbf8b/

Can you please tell me how I use both together in order to display a map on a webpage?你能告诉我我如何同时使用两者来在网页上显示地图吗? Thanks谢谢

Simple way would be:简单的方法是:

 function geoSuccess(position) { var long = position.coords.longitude; var lat = position.coords.latitude; $('.map-container').html( '<iframe width="300" height="170" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.com/maps?q=' + lat + ',' + long + '&hl=es;z=14&amp;output=embed"></iframe>' ); }; function geoFail() { /* Not supported */ }; if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(geoSuccess, geoFail); };
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="map-container"></div>

It won't work here, either on JSFiddle , but you can try in IE if you enable geolocation or on secure HTTPS website - it works just fine.它在这里不起作用,无论是在JSFiddle 上,但如果您启用地理定位或在安全的 HTTPS 网站上,您可以在 IE 中尝试 - 它工作得很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM