slovak_100
slovak_100

Reputation: 782

geocoding data or possibly IP into a google map

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

Upvotes: 0

Views: 929

Answers (1)

zer0bit
zer0bit

Reputation: 615

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>

Upvotes: 1

Related Questions