将数据或可能的 IP 地理编码到谷歌地图中

发布于 2024-11-01 08:49:39 字数 551 浏览 4 评论 0原文

我的网站上有一个捐赠部分,我对是否可以实现以下功能感兴趣:我的网站有一个捐赠者部分,我想在其中合并一个 Google 地图,其中在所有捐赠来源的位置都放置了图钉——这些位置不必是准确的(我认为 IP 地址就可以了)。

我想知道是否可以制作一个实时显示捐赠活动的谷歌地图。如果它需要实际数据(城市、州),我可以收集这些信息,因为该网站目前是按以下方式设置的:用户选择他们想要捐赠的金额,他们点击贝宝按钮,他们通过 PayPal 提交捐款,然后重新路由到感谢页面,询问姓名、城市和州(此信息通过 mySQL 存储)。用户提供此数据并点击提交(在感谢页面上)后,它们将被重新路由到捐赠者页面...这是我想要的谷歌地图,其中的引脚代表所有捐赠者和捐赠者他们来自的城市。另外,由于数据加载在 SQL 数据库中,是否可以加载包含基于该数据的所有引脚的地图,并且仍然使用新数据进行更新(实时)?最后,我使用的是 PHP——这有什么冲突吗?

如果有人可以提供任何指示,我将非常感激。我对 Google API 有点新手,所以我不确定它的功能。我还尝试查看他们的文档和论坛,但没有发现任何非常有帮助的内容。我很感谢您的宝贵时间,也感谢您提供的任何帮助!

伊万

I have a donations section on my website and I'm interested whether the following feature is possible: I have a donors portion of the site where I'd like to incorporate a Google map which has pins placed in all the locations that donations came from--these locations dont have to be exact (IP address would work fine I think).

I was wondering whether making a Google map that displays donation activity in real-time is possible. If it requires actual data (city, state) it's possible for me to gather that information, because the website is currently set-up in the following way: a user selects the amount they would like to donate, they click the paypal button, they submit their donation via paypal, get re-routed to a thank you page that asks for a name, city and state (this info is stored via mySQL). After the user provides this data and hits submit (on the thank you page), they are re-routed to the donors page... this is where i would like to have a google map with pins representing all the people who donated and the city where they are from. Also, because the data is loaded in a SQL db, would it be possible to load the map with all the pins based in this data, and still have it update with new data too (in real-time)? Finally, I'm using PHP--any conflicts with that?

If anyone can offer any pointers I'd be so thankful. I'm a bit of a novice when it comes to Google API, so I'm not sure of the capabilities. I also tried to look at their docs and forums, but did not find anything extremely helpful. I'm grateful for your time, and I thank you for any help!

Ivan

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

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

发布评论

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

评论(1

梓梦 2024-11-08 08:49:39

可以使用 W3C 地理定位 API 检索用户浏览器的地理位置。它非常深入,所以如果您不打算阅读,我已经包含了一些我正在使用的原型代码。它应该显示一个带有您当前浏览器位置的标记。

http://dev.w3.org/geo/api/spec-source.html

您可以将经度和纬度信息存储到数据库中,然后解析它并使用 javascript 将标记插入到谷歌地图中。

    <html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
  html { height: 100% }
  body { height: 100%; margin: 0px; padding: 0px }
  #map_canvas { height: 100% }
</style>
<script type="text/javascript"
    src="http://maps.google.com/maps/api/js?sensor=true">
</script>
<script type="text/javascript">
  function initialize(location) {
    var latlng = new google.maps.LatLng(location.coords.latitude,location.coords.longitude);
    var myOptions = {
      zoom: 19,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById("map_canvas"),
        myOptions);
var marker = new google.maps.Marker({
      position: latlng, 
      map: map, 
      title:"Hello World!"
  });   
  }

</script>
</head>
<body onload="navigator.geolocation.getCurrentPosition(initialize);">
  <div id="map_canvas" style="width:100%; height:100%"></div>
</body>
</html>

The geolocation of the user's browser can be retrieved using the W3C geolocation API. It's pretty in-depth so if you're not in for the reading I have included some prototype code I was playing with. It should show a marker with your current browser location.

http://dev.w3.org/geo/api/spec-source.html

You can store the longitude and latitude information into your database and later parse it and insert the markers into google maps with javascript.

    <html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
  html { height: 100% }
  body { height: 100%; margin: 0px; padding: 0px }
  #map_canvas { height: 100% }
</style>
<script type="text/javascript"
    src="http://maps.google.com/maps/api/js?sensor=true">
</script>
<script type="text/javascript">
  function initialize(location) {
    var latlng = new google.maps.LatLng(location.coords.latitude,location.coords.longitude);
    var myOptions = {
      zoom: 19,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById("map_canvas"),
        myOptions);
var marker = new google.maps.Marker({
      position: latlng, 
      map: map, 
      title:"Hello World!"
  });   
  }

</script>
</head>
<body onload="navigator.geolocation.getCurrentPosition(initialize);">
  <div id="map_canvas" style="width:100%; height:100%"></div>
</body>
</html>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文