Messages are independent and ephemeral. You’ll never have one message that has both the latitude and longitude as part of the same message given the way these are published. So you’ll always have to process these independently.
You can do a wild card subscription to subscribe to both topics using xxx/position/#
but when you get a message on xxx/position/latitude
it won’t include the longitude and when you get a message on xxx/position/longitude
you won’t get the latitude. So there is no transform that is going to give you both.
And there will always be a time when you’ve processed one but not the other. For example, a new lat/lon is published and OH will get and process the lat message first and then the lon message and inbetween you’ll have an incorrect coordinate.
The best thing to do would be to configure what ever is publishing these to publish the lat/lon as one message to one topic.
Short of that you’ll need something to get and process these messages independently and merge them later. This can be done in a transformation, but it’s going to be much more complicated and sensitive to timing. You’ll need a rule.
Separate the latitude and longitude to separate Channels. You can use an Event Topic instead of a State Topic for both of these unless for some reason you want to keep the lat and lon in separate Items.
Trigger a rule by both events or changes to the Items linked to the Channels if you choose a state topic.
In the rule you’ll need to set a short timer, maybe half a second but the best time will depend on how far apart these messages are published and processed. If a timer already exists, save the coordinate and exit. If no timer exists, save the coordinate and create a timer and in the body combine the two coordinates and update what ever Item you have.
In JS it would look something like the following, assuming event Channels using #
as the topic/message separator:
var parts = event.event.split('#');
var topic = parts[0];
var message = JSON.parse(parts[1]);
if(topic == "xxx/position/latitude") cache.private.put("latitude", message.latitude);
else if(topic == "xxx/position/longitude") cache.private.put("longitude", message.longitude);
if(!cache.private.exists("timer")) {
cache.private.put("timer", actions.ScriptExecution.createTimer(time.Duration.ofMillis(500) => {
items.MyLocation.postUpdate(cache.private.get("latitude")+","+cache.private.get("longitude"));
cache.private.remove("timer");
});
}
You can experiment with the duration to see how small of a delay is reliable.