WordPress.org

Ready to get started?Download WordPress

Forums

Google Map on WordPress Page (3 posts)

  1. roiabrazaldo
    Member
    Posted 10 months ago #

    Okay, I'm trying to insert my google map on my page,
    I manage to make the map appeared but the markers are not, I'm having a problem with my javascript, I dont see the markers

    here is my map_preload.js

    // JavaScript Document
    
    //declare namespace
    var preload = {};
    
    //declare globals
    var map;
    
    //trace function for debugging
    function trace(message)
    {
    	if (typeof console != 'undefined')
    	{
    		console.log(message);
    	}
    }
    
    //Function that gets run when the document loads
    preload.initialize = function()
    {
    	var latlng = new google.maps.LatLng(11.8728,122.8613);
    	var myOptions = {
    		zoom: 6,
    		center: latlng,
    		disableDefaultUI: false,
    		mapTypeId: google.maps.MapTypeId.ROADMAP
    	};
    	map = new google.maps.Map(document.getElementById("map-canvas"), myOptions);
     //Map schools
    	 preload.placesRequest(latlng,999999,'Lianas Supermarket','images/pin.png');
    }
    
    //Request places from Google
    preload.placesRequest = function(latlng,radius,query,icon)
    {
    	//Parameters for our places request
    	var request = {
    		location: latlng,
    		radius: radius,
    		query: query
    	};
    
    	//Make the service call to google
    	var callPlaces = new google.maps.places.PlacesService(map);
    	callPlaces.textSearch(request, function(results,status){
    		//trace what Google gives us back
    		trace(results);
    		$.each(results, function(i,place){
    			 var placeLoc = place.geometry.location;
    			 var thisplace = new google.maps.Marker({
    				 map: map,
    				 position: place.geometry.location,
    				 icon: icon,
    				 title: place.name
    			 });
    
    			 $.ajax({
    				cache: false,
    				url: 'php/get_place.php',
    				type: 'post',
    				data: 'latlang=' + place.geometry.location + '&q=' + 1
    			});
    
    			google.maps.event.addListener(thisplace, 'click', function() {
    				var infowindow = new google.maps.InfoWindow({
    						  content: "<div><center><img src=\"images/infoload.gif\"><br />loading...</center></div>"
    						});
    
    				infowindow.open(map,thisplace);
    				$.ajax({
    					cache: false,
    					url: 'php/get_place.php',
    					type: 'post',
    					data: 'latlang=' + place.geometry.location + '&q=' + 2,
    					success: function(data){
    						infowindow.close();
    						contentString = data;
    						infowindow = new google.maps.InfoWindow({
    						  content: contentString
    						});
    						infowindow.open(map,thisplace);
    					}
    				});
    			});
    		})
    	});
    
    }

    and here's the PHP get_place

    if (isset($_POST['latlang'])){
    	$latlang = $_POST['latlang'];
    }
    
    if (isset($_POST['q'])){
    	$q = $_POST['q'];
    }
    
    if($q==1){
    	$wpdb->query("INSERT IGNORE INTO <code>tbl_branch</code> SET <code>br_latlang</code> = '".$latlang."';");
    }
    else{
    	$result = $wpdb->get_results( "SELECT REPLACE(<code>br_title</code>, ' ', ' '), <code>br_content</code> FROM <code>tbl_branch</code> WHERE <code>br_latlang</code> = '".$latlang."';" );
    	$row = mysql_fetch_array($result);
    	echo "<div id=\"infobox_content\">
    		<div id=\"siteNotice\"></div>
    		<h3 id=\"firstHeading\" class=\"firstHeading\">".$row[0]."</h3>
    		<div id=\"bodyContent\">
    		".$row[1]."
    		</div>
    		</div>";
    }

    basically my get_place.php saves the latlangs given by google so I can customly add the info myself using my own data in a table. but the script doesn't get there, I think it didn't call the get_place.php in the first place

    I've tried this on non-wordpress just basic html, it worked.

    please help.

  2. roiabrazaldo
    Member
    Posted 10 months ago #

    ok i put an alert after the $.each line, and it didn't go through there.

  3. roiabrazaldo
    Member
    Posted 10 months ago #

    ok im certain the
    $.each(results, function(i,place){ doesnt work here i dont know why.. it does work on basic html, i dk what wordpress feature is interfering with it

Reply

You must log in to post.

About this Topic

Tags

No tags yet.