Support » Plugin: Leaflet Maps Marker (Google Maps, OpenStreetMap, Bing Maps) » Creating a marker by function or by any code?

Viewing 15 replies - 1 through 15 (of 20 total)
  • Hi Sascha,
    marker and layer maps are saved to separate database tables. If you want to add them to a post, page or widget, you have to use the according shortcode. The shortcode can also be used in template files with do_shortcode()-function – see http://mapsmarker.com/docs for a tutorial on that.
    best,
    Robert

    Thread Starter landwire

    (@landwire)

    Hi Robert,

    so I looked at that:
    http://www.mapsmarker.com/docs/basic-usage/how-to-create-maps-directly-by-using-shortcodes-only/

    But this does not create the marker in the database as far as I can understand. Is there a way to also create the marker in the database? Maybe I should just look at your actual code and functions. Which function is called when you actually click “Save Marker” at the backend? I assume I could just use that to create a marker with code?

    Hi Sascha,
    with the shortcode parameters from the linked doc a marker map is generated on the fly and not saved to database. Currently you would need to build upon the MapsMarker API (MapsMarker.com/mapsmarker-api) for example if you want to create a custom solution for adding maps to database. For a later pro release I plan to add better support for default wordpress processes like building maps from custom fields or custom post type. Anyway this will still need some time as I haven’t worked out all details necessary here.
    best,
    Robert

    Thread Starter landwire

    (@landwire)

    Hi Robert,
    thanks. I will look at the API.
    S

    Thread Starter landwire

    (@landwire)

    Hi Robert,
    I looked at the API, but I am quite new to API’s.
    To set a marker I would use this:

    http://your-domain/wp-content/plugins/leaflet-maps-marker/leaflet-api.php?key=YOUR_KEY&action=add&type=marker&markername=Headquarter&geocode=Main Street 1 Washington

    Now I would like to use the POST method and restrict the referrer. What would that look like in javascript/jQuery or php code? Will creating a marker create a new map? Or would I need to create a map first?
    Thanks,
    Sascha

    Hi Sascha,
    the API call url is correct – that would create a marker map.
    Anyway I’d suggest to wait about one more week till working with the API – I am just working on a new authentication method for the API which will make it more secure (by using public key, private key and expire – the old method of using only a public key will not work anymore with the next release). Will also add more examples with the next release…
    best,
    Robert

    Thread Starter landwire

    (@landwire)

    Thanks Robert,
    I will wait a week or so then.
    I guess the API call to create a new marker will then also return the new marker ID? As I will need that to save the marker ID to a certain posts custom field.
    Sascha

    yes, it returns all marker parameters after each API action

    Thread Starter landwire

    (@landwire)

    Thanks Robert!
    Once you have completed the work on the new API could you let me know how to create a new marker (and how to update a marker – so I can test out the pro version at some point) with some code in Javascript/jQuery? That would be great!
    Sascha

    Hi Sascha,
    I will be using pretty much the same authentication method as gravity forms (see http://www.gravityhelp.com/documentation/page/Web_API#Authentication for more details). Will also add a Javascript example for generating a signature you can use once the new version is released…
    best,
    Robert

    Thread Starter landwire

    (@landwire)

    Hello Robert,

    I have seen you added signature code etc. Will have to give this a shot soon! The only thing I do not know is how to create a marker with a javascript or jQuery request/code.

    Could you let me know how I would do the below POST request with jQuery or javascript?
    That would be great! Thanks,
    Sascha

    Add new marker, title Headquarter, geocode Main Street 1 Washington:

    <form action="https://your-domain/wp-content/plugins/leaflet-maps-marker-pro/leaflet-api.php" method="POST">
    <input type="hidden" name="key" value="YOUR_PUBLIC_KEY"/>
    <input type="hidden" name="signature" value="YOUR_SIGNATURE"/>
    <input type="hidden" name="expires" value="YOUR_EXPIRE_VALUE"/>
    <input type="text" name="action" value="add"/>
    <input type="text" name="type" value="marker"/>
    <input type="text" name="markername" value="Headquarters"/>
    <input type="text" name="geocode" value="Main Street 1 Washington"/>
    <input type="submit" name="submit" value="submit"/>
    </form>
    Plugin Author Robert Seyfriedsberger

    (@harmr)

    Hi Sascha,

    as I am not the best in jquery I guess you must use something like

    $.ajax({
    		url: 'https://your-domain/wp-content/plugins/leaflet-maps-marker-pro/leaflet-api.php?key=xxx&signature=xxx&expires=xxxx&action=add&type=marker&markername=Headquarters&geocode=Main Street 1 Washington',
    		dataType: 'json',
    		type: 'GET',
    		complete: function(data) {
    //handle the data.responseText
        	}
    });

    hope this helps. When I have more time I will try to add a better example.
    best,

    Robert

    Thread Starter landwire

    (@landwire)

    Ah, ok. Maybe it’s a good idea to add it all to the url as a query string!
    Never thought of that!

    Plugin Author Robert Seyfriedsberger

    (@harmr)

    Anyway I wouldnt use a pure jQuery solution here as the private key should never be visible in the code and when generating the signature with the jquery example – creating the signature with php would be the better approach regarding security….

    Thread Starter landwire

    (@landwire)

    Good point! I guess I could create the marker fully in php. Which really goes back to the initial question I asked.

    So is there a way NOT to use a form (like in your example on the MapsMarker API), but just use a line of code to create the marker?

    I looked at the following examples, but I am just not sure what will work, especially with regards to oAuth and curl. Maybe you have done this before? If not, then I will dig into it.

    http://stackoverflow.com/questions/9802788/call-a-rest-api-in-php
    http://codular.com/curl-with-php
    http://codular.com/oauth-authentication-with-instagram

    But maybe a simple insert into the database with $wpdb->insert() or ->prepare() ->query() is the best option to go for? Have not done any SQL yet, so that’s another thing to learn which surely will come in handy 🙂

Viewing 15 replies - 1 through 15 (of 20 total)
  • The topic ‘Creating a marker by function or by any code?’ is closed to new replies.