Jump to content

how to add google map to a website using php and google map api


peacehunter

Recommended Posts

Yup, what JSG said, and you would need something like cURL or the HTTP extension to complete the process of sending the form data in a URL format that the Google API will accept, and the take that response back and process it.

Link to comment
Share on other sites

You actually don't need PHP at all, Javascript could get the form data and send it to Google's services to display the map. I haven't looked into how Google does that without violating the ajax constraints (possibly submitting a form in an iframe), but it does work.

Link to comment
Share on other sites

I have found this code in google map api docs. I can not use it with html. The code is below:

 var map = new GMap2(document.getElementById("map_canvas"));var geocoder = new GClientGeocoder();function showAddress(address) {  geocoder.getLatLng(	address,	function(point) {	  if (!point) {		alert(address + " not found");	  } else {		map.setCenter(point, 13);		var marker = new GMarker(point);		map.addOverlay(marker);		marker.openInfoWindowHtml(address);	  }	}  );}

I used this html code :

<form onsubmit="showAddress(this.address.value)" action="#">	  <p>		<input type="text" id="address" name="address" size="60">		<input type="submit" value="Go!"/>	  </p>	  	  <div id="map_canvas"></div>	  </form>

Plzzz give me any suggestion about this problem..

Link to comment
Share on other sites

Are you checking for Javascript errors? I think you're missing a couple things for the map configuration, I believe there are several required configuration values you need to pass. Where is the API documentation you're using?

Link to comment
Share on other sites

Don't forget to actually load the Google Maps script, too. Also, that's API v2 code, which has been deprecated by Google in favor of version 3.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...