+1
Є відповідь

Location update for action

choffmann 8 років тому оновлений 8 років тому 6
I am tinkering around with some location based ideas and I need to be able to tell when the current location has been updated (i.e. when the user/device has moved from one set of GPS coordinates to another). I see that there is a datasourceevent attribute named "locationupdate" that is currently still in beta.

When will that feature be out of beta? Can you provide a quick example of how it should be used?

My code so far:

<action name="updatedlocation" datasource="annotations" datasourceevent="locationupdate">
<assign property="object:LABEL.text" value="[object:MAP.gpslocation]"/>
<alert message="Location changed!" />
</action>


I am not entirely certain I am using it correctly. Thank you for any help!
Can you show me the datasource tag you are using?

This feature is available in the WIRE engine 1.3, so we should be able to get it working for you.
Well, I figured out that I was likely using it wrong to begin with. I switched my datasource to this:

<datasource name="Geo" source="standard" query="location" distanceFilter="1" providertype="location"/>

and my map to this:

<map name="map" alias="MAP" width="100%" height="100%" datasource="Geo" currentlocation="yes" showuser="yes">
</map>

With this action:

<action name="updatedlocation" datasource="Geo" datasourceevent="locationupdate">
<alert message="Location changed!" />
</action>

It still doesn't work as I expected it would, but again I am not certain I am using it/understanding it correctly. I am assuming that if the user moves far enough (in this case a maximum of 1 meter) it would trigger the iOS library to send a location update to the datasourceevent listener(?) which would then trigger my action. Forgive me, I am pretty new to location based stuff (which is why I was tinkering).

I am testing on my wife's iPhone 4/iOS6.

Any chance you have an example of some working code so I can see where I am going wrong?

Thank you for your help!
Let's try a few more things.

First, change your source on the datasource from standard to Significant-Change.

Then you will also want to turn on your location tracking on the datasource. For testing you can just add it to the datasource as location="yes". This will drain the battery on the device if you leave it on all the time, so you probably only want to turn it on when you show the map or something and turn it off when you navigate away. See the assign below.


<assign property="datasource:Geo.location" value="on" />
No joy yet. I stripped out anything not related to this issue. Here is the result:


<wire>
<datasources>
<datasource name="Geo" source="significant-change" location="yes" query="location" providertype="location"/>
</datasources>
<main>
<map name="map" alias="MAP" width="100%" height="100%" datasource="Geo" currentlocation="yes" showuser="yes"></map>
</main>
<actions>
<action name="setmaplocation" oninit="yes">
<assign property="object:MAP.region" value="[object:MAP.gpslatitude] [object:MAP.gpslongitude] [object:MAP.gpslatitude] [object:MAP.gpslongitude]"/>
</action>
<action name="updatedlocation" datasource="Geo" datasourceevent="locationupdate">
<alert message="Location changed!" />
</action>
</actions>
</wire>
Ok a few things. First of all, I am testing this on an Ad-Hoc build. Also it seems as if a few of these properties need to be set using assign tags. This is something I will have to review in the documentation.

Here is a sample that works:


<wire>
<datasources>
<datasource name="geo" source="standard" query="something" providertype="location"/>
</datasources>
<main>
<map name="map" alias="MAP" width="100%" height="100%" datasource="geo" currentlocation="yes" showuser="yes"></map>
</main>
<actions>
<action name="setmaplocation" oninit="yes">
<sync>
<assign property="datasource:geo.eventDuration" value="5"/>
<assign property="datasource:geo.distanceFilter" value="5"/>
<assign property="datasource:geo.location" value="on"/>
<assign property="object:MAP.region" value="[object:MAP.gpslatitude] [object:MAP.gpslongitude] [object:MAP.gpslatitude] [object:MAP.gpslongitude]"/>
</sync>
</action>
<action name="updatedlocation" datasource="geo" datasourceevent="locationupdate">
<alert message="Location changed!" />
</action>
</actions>
</wire>