S

Forum Replies Created

Viewing 15 posts - 1 through 15 (of 43 total)
  • Author
    Posts

  • S
    Expired Member
    Post count: 62

    Thank you. I reordered it and it works now.

    in reply to: Multiple locations on the map in a listing #388558

    S
    Expired Member
    Post count: 62

    I did not understand your earlier response: “You would have to use JS to insert it somewhere”, so I was actually still trying to figure out how to have the waypoint locations show up in the map tab under the map, preferably after the starting location. I was thinking maybe there is a codex called “XXX” that allows me to implement my own JS function that displays the waypoint locations in the map tab. So just want to know if there is such a codex. e.g. add_action(‘XXX’,’add_js_functions’);

    If this is not the way to do it, can you explain a bit more how to do what I want to achieve. I am not sure what you meant by “use JS to insert it somewhere”. Do I use the code snippet? After I write the JS function to display the waypoint, what do I do to implement that function at my desired location (in the map tab under the map)?

    in reply to: Multiple locations on the map in a listing #388015

    S
    Expired Member
    Post count: 62

    Is there a geodirectory action or filter codex that allows me to execute the JS function in the map tab after the get direction button?

    in reply to: Multiple locations on the map in a listing #387940

    S
    Expired Member
    Post count: 62

    ok, thank you for the advice.

    I have another question:
    Right now, under the map in the map tab, I can see the starting location to the left of the “Get direction” button. I would like to show the waypoints as well after the starting location. How can I do that? I know how to write the function to display the waypoints but I don’t know how I can display them at the location I want, which is in the map tab after the starting location.


    S
    Expired Member
    Post count: 62

    I was able to use custom css to do it. Thanks anyways.

    in reply to: Multiple locations on the map in a listing #387454

    S
    Expired Member
    Post count: 62

    I managed to implement it. Thank you.

    I do have another question though.
    I already set up for example 10 custom fields for 10 waypoints but I do not want all 10 of them to show up in the add listing page. I want to either:
    1) add another custom field that asks how many waypoints they have and then based on the number they provide, that many waypoints will show up in the add listing page.
    2) Only waypoint 1 shows up at first. I have a button called “add more waypoint”, upon clicking on which, one more waypoint custom field will show up. This keeps going until the maximum of 10 waypoints.

    Which method do you think is easier to implement and can you give some advice on how to do it.

    in reply to: Multiple locations on the map in a listing #387355

    S
    Expired Member
    Post count: 62

    Stiofan, thank you so much! It worked nicely now.
    Will try to implement multiple waypoints. Likely to encounter some problems. Update you again.


    S
    Expired Member
    Post count: 62

    For your information, I changed the spacing setting from 20% header logo width and 80% header menu width to 0% header logo width and 100% header menu width to move the menu tabs back to the right on the home page. But I just realized that this made the logo disappear on all the other pages on my website. So I cannot use this method to move the menu tabs back to the right on the home page. Is there any other method to move the menu tabs back to the right on the home page after your code helped me to remove the logo from the top left corner of the home page? Can I only change the space setting for the header on only the home page?

    in reply to: Multiple locations on the map in a listing #387335

    S
    Expired Member
    Post count: 62

    I just got some progress.
    Below you will find my complete code snippet that I added through the plugin code snippets. Using this code, I can get the desired route (origin-1 waypoint-destination) displayed SOMETIMES. It does not always work but if you refresh the page a few times, you will see the desired route sometimes. For instance, if you refresh the page 10 times, you see the desired route (origin-1 waypoint-destination) maybe 3 times. In the other 7 times, you only see the direct route between the origin and the destination. I think the code is not stable. Also, in the code, you see I declare a variable with ID=’detail_page_map_canvas_waypoints’. Without this declaration, the code will not work at all, as in no route is shown. Also, in the code, you find me adding a line that says

    
    
    			  jQuery( '#directions' ).click(function(){ 
    				calcRouteWithWaypoints('detail_page_map_canvas');
    			  });

    Without this line, only the route between the origin and the destination is displayed, regardless of how many times I refresh the page.
    Hope you can help. I think I am getting close.

    
    
    function add_js_functions(){
    
      if(geodir_is_page('detail') || geodir_is_page('preview')){
     global $post;
    		if(isset($post->geodir_waypoint1) && $post->geodir_waypoint1 && $post->post_type=='gd_place'){
    			?>
    
    			  <p id="detail_page_map_canvas_waypoints"></p>
    			  <script>
    			  
    			  function calcRouteWithWaypoints(map_canvas){
    			  initMap(map_canvas);
    			  var optionsname = map_canvas;
    			  var map_options = eval(optionsname);
    
    			  if (window.gdMaps == 'google'){
    				// Direction map
    				directionsDisplay.setMap(jQuery.goMap.map);
    				directionsDisplay.setPanel(document.getElementById(map_canvas + "_directionsPanel"));
    				google.maps.event.addListener(directionsDisplay, 'directions_changed', function() {
    				  computeTotalDistance(directionsDisplay.directions, map_canvas);
    				});
    				jQuery('#directions-options').show();
    				//	  var waypts = [];
    				//	  var checkboxArray = document.getElementById(map_canvas+'_waypoints');
    				//	  for (var i = 0; i < checkboxArray.length; i++) {
    				//		if (checkboxArray.options[i].selected) {
    				//		  waypts.push({
    				//location: google.maps.DirectionsWaypoint[checkboxArray[i].value],
    				//			location: checkboxArray[i].value,
    				//			stopover: true
    				//		  });
    				//		}
    				//	  }
    				var waypts = [{location: document.getElementById(map_canvas+'_waypoints').value}];
    				var from_address = document.getElementById(map_canvas + '_fromAddress').value;
    				var request = {
    				  origin: from_address,
    				  destination: gd_single_marker_lat + ',' + gd_single_marker_lon,
    				  waypoints: waypts,
    				  optimizeWaypoints: true,
    				  travelMode: gdGetTravelMode(),
    				  unitSystem: gdGetTravelUnits()
    				};
    				directionsService.route(request, function(response, status) {
    				  if (status == google.maps.DirectionsStatus.OK)
    				  {
    					directionsDisplay.setDirections(response);
    					//map = new google.maps.Map(document.getElementById(map_canvas), map_options);
    					//directionsDisplay.setMap(map);
    				  } else {
    					alert(geodir_all_js_msg.address_not_found_on_map_msg + from_address);
    				  }
    				});
    			  }
    			}
      
       
    		  jQuery(function() {
    
    			if(jQuery('#detail_page_map_canvas_fromAddress').length){
    			  jQuery('#detail_page_map_canvas_fromAddress').val('<?php echo esc_html($post->geodir_startpoint);?>');
    			  if(jQuery('#detail_page_map_canvas_waypoints').length){
    				jQuery('#detail_page_map_canvas_waypoints').val('<?php echo esc_html($post->geodir_waypoint1);?>');}
    
    			  jQuery( '#directions' ).click(function(){ 
    				calcRouteWithWaypoints('detail_page_map_canvas');
    			  });
    			  jQuery('#directions').trigger('click');
    			}
    
    			jQuery('.geodir-tab-head a[data-tab="#post_map"]').click(function(){
    			  calcRouteWithWaypoints('detail_page_map_canvas');
    			});
    			jQuery('.geodir-tab-head a[data-tab="#post_map"]').click(function(){
    			  jQuery('#directions').trigger('click');
    			});
    
    		  });
    		  
    	</script>
    <?php	  
      
      
      		}
      	}
      }
    add_action('wp_footer','add_js_functions');
    in reply to: Multiple locations on the map in a listing #387322

    S
    Expired Member
    Post count: 62
    
    
    function calcRouteWithWaypoints(map_canvas){
    			initMap(map_canvas);
    			var optionsname = map_canvas;
    			var map_options = eval(optionsname);
    
    			
    			if (window.gdMaps == 'google'){
    			  // Direction map
    			  directionsDisplay.setMap(jQuery.goMap.map);
    			  directionsDisplay.setPanel(document.getElementById(map_canvas + "_directionsPanel"));
    			  google.maps.event.addListener(directionsDisplay, 'directions_changed', function() {
    				computeTotalDistance(directionsDisplay.directions, map_canvas);
    			  });
    			  jQuery('#directions-options').show();
    		//	  var waypts = [];
    		//	  var checkboxArray = document.getElementById(map_canvas+'_waypoints');
    		//	  for (var i = 0; i < checkboxArray.length; i++) {
    		//		if (checkboxArray.options[i].selected) {
    		//		  waypts.push({
    					//location: google.maps.DirectionsWaypoint[checkboxArray[i].value],
    		//			location: checkboxArray[i].value,
    //					stopover: true
    		//		  });
    		//		}
    		//	  }
    			  var waypts = [{location: document.getElementById(map_canvas+'_waypoints').value}];
    			  var from_address = document.getElementById(map_canvas + '_fromAddress').value;
    			  var request = {
    				origin: from_address,
    				destination: gd_single_marker_lat + ',' + gd_single_marker_lon,
    				waypoints: waypts,
    //				optimizeWaypoints: true,
    //				travelMode: gdGetTravelMode(),
    				travelMode: google.maps.DirectionsTravelMode.WALKING,
    //				unitSystem: gdGetTravelUnits()
    				unitSystem: google.maps.DirectionsUnitSystem.METRIC
    			  };
    			  directionsService.route(request, function(response, status) {
    				if (status == google.maps.DirectionsStatus.OK)
    				  {
    				  directionsDisplay.setDirections(response);
    				  //map = new google.maps.Map(document.getElementById(map_canvas), map_options);
    				  //directionsDisplay.setMap(map);
    				} else {
    				  alert(geodir_all_js_msg.address_not_found_on_map_msg + from_address);
    				}
    			  });
    			}
    		  }

    Thank you. I added your code and replaced map_canvas in the code with ‘detail_page_map_canvas’. Also, I found that checkboxArray[i].value does not work for me probably because my detail_page_map_canvas_waypoints variable can only take one value. I will ask about that later. Right now, my calcRouteWithWaypoints is updated as above. My map still shows only the original route between origin and destination and fails to show the waypoint.

    in reply to: Multiple locations on the map in a listing #387066

    S
    Expired Member
    Post count: 62

    Hi Stiofan, sorry I don’t really understand. Can you give a bit more detail about that? With more details or clearer explanation, I can google and try to implement the code.

    Also, was it correct that I used one code snippet to add the JS function that calculates and displays the route and then used another code snippet to assign my html variable of the custom field to the variable called detail_page_map_canvas_waypoints?

    Thanks for your patience.

    in reply to: Multiple locations on the map in a listing #386891

    S
    Expired Member
    Post count: 62

    ok thank you. I will try it. Another question is I don’t see where I am calling my JS function calcRouteWithWaypoints. How do I call that function?

    in reply to: Multiple locations on the map in a listing #386741

    S
    Expired Member
    Post count: 62

    I am not sure if I understand correctly but here is what I did.
    I added a code snippet to add the JS function.

    
    
    function add_js_functions(){
    ?>
    <script>
    function calcRouteWithWaypoints(map_canvas){
        initMap(map_canvas);
        var optionsname = map_canvas;
        var map_options = eval(optionsname);
    
    if (window.gdMaps == 'google'){
            // Direction map
            directionsDisplay.setMap(jQuery.goMap.map);
            directionsDisplay.setPanel(document.getElementById(map_canvas + "_directionsPanel"));
            google.maps.event.addListener(directionsDisplay, 'directions_changed', function() {
                computeTotalDistance(directionsDisplay.directions, map_canvas);
            });
            jQuery('#directions-options').show();
            var waypts = [];
            var checkboxArray = document.getElementById(map_canvas+'_waypoints');
            for (var i = 0; i < checkboxArray.length; i++) {
              if (checkboxArray.options[i].selected) {
                waypts.push({
                  location: checkboxArray[i].value,
                  stopover: true
                });
              }
            }
    
    		var from_address = document.getElementById(map_canvas + '_fromAddress').value;
            var request = {
                origin: from_address,
                destination: gd_single_marker_lat + ',' + gd_single_marker_lon,
                waypoints: waypts,
    	     	optimizeWaypoints: true,
    	     	travelMode: gdGetTravelMode(),
                unitSystem: gdGetTravelUnits()
            };
            directionsService.route(request, function(response, status) {
                if (status == google.maps.DirectionsStatus.OK) {
                    directionsDisplay.setDirections(response);
                    //map = new google.maps.Map(document.getElementById(map_canvas), map_options);
                    //directionsDisplay.setMap(map);
                } else {
                    alert(geodir_all_js_msg.address_not_found_on_map_msg + from_address);
                }
            });
        }
    }
    </script>
    <?php
    }
    add_action('wp_footer','add_js_functions');
    '
    
    and then I added another code snippet to assign waypoint1 (the html variable of a field I created for user to enter their first stopover) to the Jquery variable #detail_page_map_canvas_waypoints by PHP.
    
    

    add_action(‘wp_footer’,’_my_map_route2′);
    function _my_map_route2(){
    if(geodir_is_page(‘detail’) || geodir_is_page(‘preview’)){
    global $post;
    if(isset($post->geodir_waypoint1) && $post->geodir_waypoint1 && $post->post_type==’gd_place’){
    ?>
    <script>
    jQuery(function() {

    if(jQuery(‘#detail_page_map_canvas_waypoints’).length){
    jQuery(‘#detail_page_map_canvas_waypoints’).val(‘<?php echo esc_html($post->geodir_waypoint1);?>’);
    jQuery(‘#directions’).trigger(‘click’);
    }

    jQuery(‘.geodir-tab-head a[data-tab=”#post_map”]’).click(function(){
    jQuery(‘#directions’).trigger(‘click’);
    });

    });
    </script>
    <?php
    }
    }
    }’

    Hope you can point out my mistakes.


    S
    Expired Member
    Post count: 62

    Thank you. It worked. I also changed the spacing setting of the header to move all the tabs in the header back to their original positions on the right.

    in reply to: Multiple locations on the map in a listing #386579

    S
    Expired Member
    Post count: 62

    I create my own JS function called “calcRouteWithWaypoints” that can be added to map.js. It is basically the same as the calcRoute function except that I added the waypts variable which is then included in the request variable. In the “gdMyGeoGetDirections” function in map.js, I call calcRouteWithWaypoints instead of calcRoute. I see that there is a “_fromAddress” ID. How or where do I create a “_waypoints” ID? If I can do that, I will use code snippet to assign new custom field variables (that a user can input) to the waypoints ID. ******************************************************************************************************
    function calcRouteWithWaypoints(map_canvas) {
    initMap(map_canvas);
    var optionsname = map_canvas;
    var map_options = eval(optionsname);

    if (window.gdMaps == ‘google’) {
    // Direction map
    directionsDisplay.setMap(jQuery.goMap.map);
    directionsDisplay.setPanel(document.getElementById(map_canvas + “_directionsPanel”));
    google.maps.event.addListener(directionsDisplay, ‘directions_changed’, function() {
    computeTotalDistance(directionsDisplay.directions, map_canvas);
    });
    jQuery(‘#directions-options’).show();
    var waypts = [];
    var checkboxArray = document.getElementById(map_canvas + ‘_waypoints’);
    for (var i = 0; i < checkboxArray.length; i++) {
    if (checkboxArray.options[i].selected) {
    waypts.push({
    location: checkboxArray[i].value,
    stopover: true
    });
    }
    }

    var from_address = document.getElementById(map_canvas + ‘_fromAddress’).value;
    var request = {
    origin: from_address,
    destination: gd_single_marker_lat + ‘,’ + gd_single_marker_lon,
    waypoints: waypts,
    optimizeWaypoints: true,
    travelMode: gdGetTravelMode(),
    unitSystem: gdGetTravelUnits()
    };
    directionsService.route(request, function(response, status) {
    if (status == google.maps.DirectionsStatus.OK) {
    directionsDisplay.setDirections(response);
    //map = new google.maps.Map(document.getElementById(map_canvas), map_options);
    //directionsDisplay.setMap(map);
    } else {
    alert(geodir_all_js_msg.address_not_found_on_map_msg + from_address);
    }
    });
    }
    }
    ****************************************************************************************************

    Thank you for your help.

Viewing 15 posts - 1 through 15 (of 43 total)