如何使用 javascript 在我的网站中显示外部内容

发布于 2024-10-18 20:35:25 字数 1657 浏览 1 评论 0原文

这是我的第一篇文章! 我有一个关于 javascript 的问题...这是我的代码:

 <html>
  <head>
    <title>Geolocation Demo</title>
  </head>
  <body>
    <h1>Geolocation Demo</h1>
    <p>Latitude: <span id="lat">0.00</span> Longitude: <span id="lon">0.00</span> City: <span id="city">Loading...</span></p>
    <p><a id="city_link" href="http://tinygeocoder.com/" target="_blank">View City</a></p>
    <p><a id="gmaps_link" href="http://maps.google.co.uk/" target="_blank">View on Google Maps</a></p>

    <script language="javascript">
       // show the position on the page and make a google maps link
       function showPosition(position) {
         var lat = position.coords.latitude;
         var lon = position.coords.longitude;
         document.getElementById("lat").innerHTML = lat;
         document.getElementById("lon").innerHTML = lon;

         var gmaps_url = "http://maps.google.co.uk/maps?f=q&source=s_q&hl=en&geocode=&q=" + lat + "+" + lon;
         var city_url = "http://tinygeocoder.com/create-api.php?g=" + lat + "," + lon;
         document.getElementById("gmaps_link").href = gmaps_url;
         document.getElementById("city_link").href = city_url;
         }
    </script>
 </body>
 </html>

如您所见,该脚本针对我的地理位置。具体来说,纬度和经度运行良好。此外,我想显示区域信息(如城市)。因此,我找到了一个提供坐标的网站,它返回了一个区域名称。我的问题是,我是否可以在不单击“查看城市”链接但在“城市”字段中显示区域名称......是否可以传递网页内容(http://tinygeocoder.com/create-api.html)。 php?g=" + lat + "," + lon;) 进入我的网页?此页面的内容只是我所说的名称...没有 html 标签!

谢谢!

This is my first post!
I have a question about javascript...here is my code:

 <html>
  <head>
    <title>Geolocation Demo</title>
  </head>
  <body>
    <h1>Geolocation Demo</h1>
    <p>Latitude: <span id="lat">0.00</span> Longitude: <span id="lon">0.00</span> City: <span id="city">Loading...</span></p>
    <p><a id="city_link" href="http://tinygeocoder.com/" target="_blank">View City</a></p>
    <p><a id="gmaps_link" href="http://maps.google.co.uk/" target="_blank">View on Google Maps</a></p>

    <script language="javascript">
       // show the position on the page and make a google maps link
       function showPosition(position) {
         var lat = position.coords.latitude;
         var lon = position.coords.longitude;
         document.getElementById("lat").innerHTML = lat;
         document.getElementById("lon").innerHTML = lon;

         var gmaps_url = "http://maps.google.co.uk/maps?f=q&source=s_q&hl=en&geocode=&q=" + lat + "+" + lon;
         var city_url = "http://tinygeocoder.com/create-api.php?g=" + lat + "," + lon;
         document.getElementById("gmaps_link").href = gmaps_url;
         document.getElementById("city_link").href = city_url;
         }
    </script>
 </body>
 </html>

As you can see, this script target my geolocation. Specifically, Lat and Lon are working perfectly. In addinition, i want to display and region info (like city). So, i found a website which i provide the coordinates and it returns me a region name. My question is if i can display the name of region without clicking the link "View city" but in the field "city"...is it possible to pass the webpage content (http://tinygeocoder.com/create-api.php?g=" + lat + "," + lon;) into my webpage? The content of this page is only the name as i said...no html tags!

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

七分※倦醒 2024-10-25 20:35:25

使用 AJAX

形成 url 后,向其发出 ajax 请求,
获取结果并解析到您的容器中

您可能还想查看谷歌地理编码器示例(当我检查该服务时,它说它不可用)

Use AJAX

After you have the url formed make a ajax request to it,
get the results back and parse into your container

You might also want to look at the google geocoder example (as when I checked that service it said it was unavailable)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文