Title: Creating a marker by function or by any code?
Last modified: August 21, 2016

---

# Creating a marker by function or by any code?

 *  Resolved [landwire](https://wordpress.org/support/users/landwire/)
 * (@landwire)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/creating-a-marker-by-function-or-by-any-code/)
 * Hi there,
 * I was wondering if it is at all possible to create a marker simply with code?
   I am not sure how the markers are saved. Are they custom post types? I guess 
   then I would need to create a post, which obviously can be done.
 * Any hints would be great.
    Sascha
 * [https://wordpress.org/plugins/leaflet-maps-marker/](https://wordpress.org/plugins/leaflet-maps-marker/)

Viewing 15 replies - 1 through 15 (of 20 total)

1 [2](https://wordpress.org/support/topic/creating-a-marker-by-function-or-by-any-code/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/creating-a-marker-by-function-or-by-any-code/page/2/?output_format=md)

 *  Plugin Author [Robert Seyfriedsberger](https://wordpress.org/support/users/harmr/)
 * (@harmr)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/creating-a-marker-by-function-or-by-any-code/#post-4582061)
 * 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](http://mapsmarker.com/docs) for a tutorial on
   that. best, Robert
 *  Thread Starter [landwire](https://wordpress.org/support/users/landwire/)
 * (@landwire)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/creating-a-marker-by-function-or-by-any-code/#post-4582078)
 * Hi Robert,
 * so I looked at that:
    [http://www.mapsmarker.com/docs/basic-usage/how-to-create-maps-directly-by-using-shortcodes-only/](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?
 *  Plugin Author [Robert Seyfriedsberger](https://wordpress.org/support/users/harmr/)
 * (@harmr)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/creating-a-marker-by-function-or-by-any-code/#post-4582113)
 * 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](https://wordpress.org/support/users/landwire/)
 * (@landwire)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/creating-a-marker-by-function-or-by-any-code/#post-4582150)
 * Hi Robert,
    thanks. I will look at the API. S
 *  Thread Starter [landwire](https://wordpress.org/support/users/landwire/)
 * (@landwire)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/creating-a-marker-by-function-or-by-any-code/#post-4582280)
 * 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](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
 *  Plugin Author [Robert Seyfriedsberger](https://wordpress.org/support/users/harmr/)
 * (@harmr)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/creating-a-marker-by-function-or-by-any-code/#post-4582281)
 * 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](https://wordpress.org/support/users/landwire/)
 * (@landwire)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/creating-a-marker-by-function-or-by-any-code/#post-4582282)
 * 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
 *  Plugin Author [Robert Seyfriedsberger](https://wordpress.org/support/users/harmr/)
 * (@harmr)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/creating-a-marker-by-function-or-by-any-code/#post-4582283)
 * yes, it returns all marker parameters after each API action
 *  Thread Starter [landwire](https://wordpress.org/support/users/landwire/)
 * (@landwire)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/creating-a-marker-by-function-or-by-any-code/#post-4582289)
 * 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
 *  Plugin Author [Robert Seyfriedsberger](https://wordpress.org/support/users/harmr/)
 * (@harmr)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/creating-a-marker-by-function-or-by-any-code/#post-4582290)
 * 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](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](https://wordpress.org/support/users/landwire/)
 * (@landwire)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/creating-a-marker-by-function-or-by-any-code/#post-4582294)
 * 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](https://wordpress.org/support/users/harmr/)
 * (@harmr)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/creating-a-marker-by-function-or-by-any-code/#post-4582296)
 * 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](https://wordpress.org/support/users/landwire/)
 * (@landwire)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/creating-a-marker-by-function-or-by-any-code/#post-4582298)
 * 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](https://wordpress.org/support/users/harmr/)
 * (@harmr)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/creating-a-marker-by-function-or-by-any-code/#post-4582299)
 * 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](https://wordpress.org/support/users/landwire/)
 * (@landwire)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/creating-a-marker-by-function-or-by-any-code/#post-4582300)
 * 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://stackoverflow.com/questions/9802788/call-a-rest-api-in-php)
   
   [http://codular.com/curl-with-php](http://codular.com/curl-with-php) [http://codular.com/oauth-authentication-with-instagram](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)

1 [2](https://wordpress.org/support/topic/creating-a-marker-by-function-or-by-any-code/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/creating-a-marker-by-function-or-by-any-code/page/2/?output_format=md)

The topic ‘Creating a marker by function or by any code?’ is closed to new replies.

 * ![](https://ps.w.org/leaflet-maps-marker/assets/icon.svg?rev=970936)
 * [Leaflet Maps Marker (Google Maps, OpenStreetMap, Bing Maps)](https://wordpress.org/plugins/leaflet-maps-marker/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/leaflet-maps-marker/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/leaflet-maps-marker/)
 * [Active Topics](https://wordpress.org/support/plugin/leaflet-maps-marker/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/leaflet-maps-marker/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/leaflet-maps-marker/reviews/)

 * 20 replies
 * 2 participants
 * Last reply from: [Robert Seyfriedsberger](https://wordpress.org/support/users/harmr/)
 * Last activity: [12 years, 3 months ago](https://wordpress.org/support/topic/creating-a-marker-by-function-or-by-any-code/page/2/#post-4582305)
 * Status: resolved