Ajax response not working for setCenter() etc

Home Forums MapPress Support Ajax response not working for setCenter() etc

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #13068
    backbeat
    Participant

    I’m trying to get the map to recenter and zoom after user inputs ZIP or address in a form field.

    I’ve gotten the form ajax working and returning the lat & lng, but the page is crashing when I try to use the ajax response in the mapp0.setCenter() method.

    Here is my ajax call:

    jQuery("#zoomer").submit(function()	{
    			var address = jQuery('#address').val();
    				jQuery.ajax({
    					url: "<?php echo admin_url('admin-ajax.php'); ?>", 
    					type: 'POST',
    					data: {
    							action: 'map_zoom',
    							address: address
    					},
    					success: function(response) {
    						
    						//alert(response);
    						jQuery(mapp0.setCenter(response));
    						jQuery(mapp0.setZoom(9));
    					}
    
    				});
    	return false;
    		
    	}); 

    Any ideas?

    Thanks.

    #13071
    Chris
    Keymaster

    Hi,

    I don’t think you want to wrap your function calls in jQuery(). Try:
    mapp0.setCenter(response);

    Instead of:
    jQuery(mapp0.setCenter(response));

    #13072
    backbeat
    Participant

    Thanks Chris,

    Just tried that and the setCenter(response) is still crashing the page.

    When I alert(response) I get a valid lat, long in the alert, but seems like setCenter doesn’t like it. Could it be that the ajax response is not in the correct format for setCenter()? It all works fine if I manually add lat and long to the setCenter() function.

    I can send you a link to the site if that would help, but I’d rather not post it here.

    Thanks,
    Mike

    #13073
    Chris
    Keymaster

    Hi Mike,

    Feel free to send a link if you like.

    SetCenter takes TWO arguments, a lat and a lng – not a structure. You can try hardcoding it to see:

    mapp0.setCenter(-32,22);

    #13074
    backbeat
    Participant

    Hey Chris, I figured this out. Thanks for the help and thanks for a great plugin!

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.