Jump to content

Anyone know of a php script that auto-maps locations?


wolfcry

Recommended Posts

Hey all,

 

Not sure if this is the proper place for my question and if it isn't, I apologize in advance.

 

I've recently began building this website and one of the desired aspects is to allow their users to input their location (city, state / province and country) and have PHP automatically create markers on a map of the location. I'm not sure PHP can even do this, sounds more like a JavaScript / Ajax thing but does anyone know of a script or open source program that can do what I'm describing? or at least can provide me some direction because I have absolutely no idea on where to start looking and before someone suggests GoogleMaps, they're storing the information locally so GoogleMaps won't work in this case as far as I know.

 

Thanks for any help you can provide!

 

Link to comment
Share on other sites

Ok, I naturally assumed someone would suggest GoogleMaps, but seeing as they want custom markers based on various user status and they want the map to auto-update based on location entered by the user and from what I've seen on GoogleMaps API (unless I'm looking at the wrong API), the locations (coordinates) are predetermined within the script itself and I don't see where the I can customize the markers themselves.

 

So, how do I go about doing this with GoogleMaps API? I'm sure I'm just missing something.

Link to comment
Share on other sites

This will add two markers to the map

 

<script type="text/javascript"> 
function initialize() {
	var myLatlng = new google.maps.LatLng(38.891033, -96.591797);
	var myOptions = {
		zoom: 3,
		center: myLatlng,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	}
	var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
	var myLatlng, marker;
	myLatlng = new google.maps.LatLng("44.6307","-93.3034");
		marker = new google.maps.Marker({
		  position: myLatlng,
		  map: map,
		  title:"24.197.217.40"
	  });
	  myLatlng = new google.maps.LatLng("44.8205","-92.9256");
		marker = new google.maps.Marker({
		  position: myLatlng,
		  map: map,
		  title:"174.155.1.75"
	  });
}

function loadScript() {
	var script = document.createElement("script");
	script.type = "text/javascript";
	script.src = "http://maps.google.com/maps/api/js?sensor=false&callback=initialize";
	document.body.appendChild(script);
}
</script> 
<div id="map_canvas" style="width: 500px; height: 300px"></div> 
<script>loadScript();</script>

Link to comment
Share on other sites

No, they are not. You can either use the GClientGeocoder and use AJAX to store the returned values or use their Geocoding webservice API directly from PHP.

 

I didn't even know about GClientGeocoder, thanks for the heads up. Also, when I stated, "They're storing the information locally" I meant the user's information is being stored locally in their (the client's) own internal database.

 

Thanks for the code snippet Little Guy, I'll see what I can do with it. Unfortunately I'm not sure if it's going to be what they want because the site owner wants that information created dynamically when the user inputs it in and as far as I know, they don't want to do that using a predetermined list of coordinates but rather general city, state/province, country stuff.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.