Wikimedia Developer Support

Add map coordinate in Wikidata

Hello, I am working on a user script that will add the coordinates. For that, I using following API

var snakData = '{ "latitude":' + newCoords[0] + ',"longitude":' + newCoords[1] + ',"precision": 0.016666666666667,"globe":"http://www.wikidata.org/entity/Q2"}';

var api = new mw.ForeignApi( 'https://www.wikidata.org/w/api.php' );

api.postWithToken( 'csrf', {
    "action": "wbcreateclaim",
    "entity": item,
    "snaktype": "value",
    "property": "P625",
    "summary": "Add/Modify Geo Coordinate",
    "value": snakData,
    "format": "json"
} ).done( function ( data ) {
    console.log( data ); 
} ).fail( function ( data ) {
    console.log( data );
} );

It adds a statement in item (Expected). But on the second time, It adds a another statement even statement is already there. So will I have to create another function to check P615 is exist or not? or there is any other wikidata API which will create or modify the current map coordinate.

And another thing, What the mean by precision in snakData? I am not able to add coordinate with precision.

Thank your :slight_smile:

1 Like

Yes, you’ll have to check for existing statements yourself – the API doesn’t do that for you (in principle, it’s okay to have several statements with the same value, though for coordinates it’s rarely useful). To edit existing statements, you can use e. g. wbsetclaimvalue, wbsetclaim or wbeditentity.

And What the mean by precision in snakData?

The precision for coordinates (general documentation, JSON documentation) records how much of the coordinates is actually significant – for example, the precision for the coordinates of an individual building would typically be higher than that of an entire city. (I think a higher precision is actually represented as a smaller numerical value, but I’m not too familiar with this, to be honest.)