views:

468

answers:

3

The Google Ajax API playground (http://code.google.com/apis/ajax/playground/?exp=maps#map_markers) provides a nice exemple to add random markers to any map:

function initialize() {
  if (GBrowserIsCompatible()) {
    var map = new GMap2(document.getElementById("map_canvas"));
    map.setCenter(new GLatLng(37.4419, -122.1419), 9);

    // Add 10 markers to the map at random locations
    var bounds = map.getBounds();
    var southWest = bounds.getSouthWest();
    var northEast = bounds.getNorthEast();
    var lngSpan = northEast.lng() - southWest.lng();
    var latSpan = northEast.lat() - southWest.lat();
    for (var i = 0; i < 10; i++) {
      var point = new GLatLng(southWest.lat() + latSpan * Math.random(),
                              southWest.lng() + lngSpan * Math.random());
      map.addOverlay(new GMarker(point));
    }
  }
}

BUT if your LatLng are next to the sea (or if you use another Zoomlevel than the exemple provided), How do you make sure your marker will avoid being placed on the sea ? Is there a flag that I can use to test if the potential LatLng of the random point is in the sea or on land ???

Txs in advance.

Hubert

A: 

I don't know about the Google Earth API but you can achieve this another way. Download the Nasa blue marble bathymetry map and create a bitmap of sea areas. Then map these coords to long/lat and you have a way to test for seas and lakes that you can use in conjunction with the google maps api.

SpliFF
Thanks for your answer but I would be surprised if there was not an easier way than this ? a sort of "property" or function on LatLng than returns a boolean (YES) if on land ? I've searched for "land" "sea" etc in the Google reference (http://code.google.com/intl/fr-FR/apis/maps/documentation/reference.html) but can't find anything... still searching further.
Hubert
Perhaps there is but since the primary reason for writing the google maps API is to mark businesses on a map I'd have to say the concept of randomly tagging areas based on elevation may be outside the scope of the API's features.On that note there may be a way to query elevation based on a point and if so your answer lies there. As far as I know sea-level is generally (but not always) pretty close to the "mean sea level" (the average height of all oceans). If you establish a location is lower than "mean sea level" that may be good enough.
SpliFF
and by "good enough" I mean for your purpose. It is NOT a fact that all land below sea level is actually inundated by sea.
SpliFF
I see your point, txs. I will investigate further and return here if I find something interesting that I can share with the community. Cheers everyone. H.
Hubert
maybe I should try the following : http://www.geonames.org/export/web-services.html#countrycode If I dont get a country code its on water ... i'll give it a try ... ?
Hubert
+1  A: 

One possibility would be to send a reverse geocode request for every point you generate. Points over water would return a "G_GEO_UNKNOWN_ADDRESS" (602) status code. However, you'll need to test it thoroughly to make sure that it will work. It's possible that a few locations on land might be returned as unknown.

Chris B
That's great. Txs.
Hubert
A: 

I'm creating a C# program that takes the users input as where they want to go and then based on that, it points them to a random location that matches their specifications.

"http://maps.google.com/maps/geo?q=29,-55" is the webpage that i'll use to determine if it's on land or not.. take a look at the specific "Accuracy: 0" string of the results of a page. If it's accuracy 0 then it's in the ocean. If it's 1 or higher then it's on land.

josh o