Basic google maps/javascript help

Sonny Forelli

Well-known member
May 8, 2008
2,330
89
48
Liberty City
I have the following code that I'm using to generate a user's map (was initially showing traffic hence the traffic stuff int he code).

All I"m trying to do is add random markers via google's example code here:

Google Maps JavaScript API Example: Simple Markers

I however can't make it work.

Can anyone help me out? Beer on me via paypal if you do.

Code:
<!--
 Copyright 2008 Google Inc. 
 Licensed under the Apache License, Version 2.0: 
 http://www.apache.org/licenses/LICENSE-2.0 
 -->
<html>
<head>
  <script type="text/javascript" src="http://www.google.com/jsapi?key=MMMMYYYYYYYYYYAAAAAAAPPPPPPIIIIIIIIIIIIKKKKKEEEEYYYYYYYYYYYY"></script>
  <script>
  google.load("maps", "2", {callback: initialize});

  function initialize() {
    // Initialize default values
    var zoom = 3;
    var latlng = new google.maps.LatLng(37.4419, -100.1419);
    var location = "Showing default location for map.";
    var map;
    var trafficInfo;
    var trafficOptions = {incidents:true};


    // If ClientLocation was filled in by the loader, use that info instead
    if (google.loader.ClientLocation) {
      zoom = 12;
      latlng = new google.maps.LatLng(google.loader.ClientLocation.latitude, google.loader.ClientLocation.longitude);
      location = "Showing IP-based location: <b>" + getFormattedLocation() + "</b>";
    } 
   
    document.getElementById("location").innerHTML = location;
    var map = new google.maps.Map2(document.getElementById('map'));
    map.setCenter(latlng, zoom);
    map.addControl(new GLargeMapControl());
   // map.addControl(new GMapTypeControl());
   


  }
    function getFormattedLocation() {
    if (google.loader.ClientLocation.address.country_code == "US" &&
      google.loader.ClientLocation.address.region) {
      return google.loader.ClientLocation.address.city + ", " 
          + google.loader.ClientLocation.address.region.toUpperCase();
    } else {
      return  google.loader.ClientLocation.address.city + ", "
          + google.loader.ClientLocation.address.country_code;
          
               }
  }

</script>
</head>
<body style="background: #f1f1f1;">
<div style="width:500;height:350; border: 2px solid #666666;" id="map"></div>
<div id="location"></div>
</body>
</html>
 


Thanks, however just looked through that can't easily see how to get it to default to a user's location nor add random map points within the map of said user's location.

I think I'm close above, the geolocation works and within the google example they have the math for the random points bounded by the box/zoom shown to the user. I just can't get them to mesh.
 
got it working, now trying to figure out how to make it so that it doesn't randomly plot on water (that is, limits the randomness to land or perhaps "known" addresses/listings only).