Jump to content

Google Maps help


unplugged_web

Recommended Posts

I wonder if somebody could help me please. I have a database with a list of areas and I want them to be displayed on a google map around where somebody is but I'm not sure how to do this.I know how to get the areas along with a description from the database, but I'm not sure how to get it so that it can be displayed on the maps so would be grateful for any help please.Here's an example of what I'm trying to do: Click hereAt the moment I'm using this to geolocate where somebody is:

<link href="http://code.google.com/apis/maps/documentation/javascript/examples/default.css" rel="stylesheet" type="text/css" /><script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script><script type="text/javascript" src="http://code.google.com/apis/gears/gears_init.js"></script><script type="text/javascript">var initialLocation;var siberia = new google.maps.LatLng(51.30, 0.31);var newyork = new google.maps.LatLng(51.30, 0.31);var browserSupportFlag =  new Boolean();var map;var infowindow = new google.maps.InfoWindow();  function initialize() {  var myOptions = {	zoom: 6,	mapTypeId: google.maps.MapTypeId.ROADMAP  };  map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);    // Try W3C Geolocation method (Preferred)  if(navigator.geolocation) {	browserSupportFlag = true;	navigator.geolocation.getCurrentPosition(function(position) {	  initialLocation = new google.maps.LatLng(position.coords.latitude,position.coords.longitude);	  contentString = "You are here";	  map.setCenter(initialLocation);	  infowindow.setContent(contentString);	  infowindow.setPosition(initialLocation);	  infowindow.open(map);	}, function() {	  handleNoGeolocation(browserSupportFlag);	});  } else if (google.gears) {	// Try Google Gears Geolocation	browserSupportFlag = true;	var geo = google.gears.factory.create('beta.geolocation');	geo.getCurrentPosition(function(position) {	  initialLocation = new google.maps.LatLng(position.latitude,position.longitude);	  contentString = "You are here";	  map.setCenter(initialLocation);	  infowindow.setContent(contentString);	  infowindow.setPosition(initialLocation);	  infowindow.open(map);	}, function() {	  handleNoGeolocation(browserSupportFlag);	});  } else {	// Browser doesn't support Geolocation	browserSupportFlag = false;	handleNoGeolocation(browserSupportFlag);  }}function handleNoGeolocation(errorFlag) {  if (errorFlag == true) {	initialLocation = newyork;	contentString = "Sorry we couldn't find your location";  } else {	initialLocation = siberia;	contentString = "Error: Your browser doesn't support geolocation. Are you in Siberia?";  }  map.setCenter(initialLocation);  infowindow.setContent(contentString);  infowindow.setPosition(initialLocation);  infowindow.open(map);}</script></head><body onLoad="initialize()">  <div id="map_canvas"></div></body></html>

Thanks

Link to comment
Share on other sites

If you have the addresses, you can use the geocoder class to convert addresses to lat/long.

  <script type="text/javascript">  var geocoder = new google.maps.Geocoder();  geocoder.geocode( { 'address': '{*address}'}, function(results, status) {	if (status == google.maps.GeocoderStatus.OK) {	  var opts = {		center: results[0].geometry.location,		mapTypeId: google.maps.MapTypeId.HYBRID,		zoom: 16,		sensor: false	  };	  var map = new google.maps.Map(document.getElementById("map"), opts);	  	  var market = new google.maps.Marker({		map: map,		position: results[0].geometry.location,		title: '{*address}',		visible: true	  });	} else {	  alert("Map could not be shown for the following reason: " + status);	}  });  </script>

"{*address}" in that example would be the address you're looking for.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...