Hoppa till huvudinnehållet

Is it possible to initialize map extent by custom command

Kommentarer

4 kommentarer

  • Phil MacIntyre

    Hi Jack,

    Phil from the Mobile team here. The out of the box geolocation component is an easy tool available to you if you'd rather avoid Workflows. If you simply load the mobile default template in Mobile App Designer, it will be present in the bottom right slot:

    Clicking/tapping on the icon once will enable "Follow Me' mode, which will center the screen on your blue user dot and move the map to follow (but will not change orientation).

    Clicking/tapping on it again will enable "Flashlight Mode", which will center the screen on your user dot and follow orientation changes (assuming your device can detect orientation). For devices that don't support orientation (e.g., a Windows desktop or laptop), the flashlight will simply continue to point north on your map.

    If you want to drive these by commands, Follow Me mode is the equivalent of 'geolocation.auto-recenter' and Flashlight mode is the equivalent of 'geolocation.auto-recenter-and-reorient'. I was able get both of these working with a custom command in Designer like so:

    That said, we have to be able to get your location first before those commands can take effect. It can often take a little time for the signal to become available to us through the Runtime, so using a mapOnInitialized event might not work (as it will fire as soon as the map is loaded, but we might not have your location then). Android & iOS tend to report locations very quickly, but we've seen that Windows devices often have a delay in reporting their position (as confirmed by referencing other geolocating software). The geolocation component again is useful here, as it will update state to display your current status. If we can't currently get a location for your device, the icon will indicate that as so:

    Hope that helps,

    Phil MacIntyre

    0
  • Jack Zhang

    Hi @..., thank you for the response with the details. Yes you're correct, my goal is to center and zoom the map to the user location automatically after the map is initialised, just like how it behaves in the Google Map app. Therefore I put the "geolocation.auto-recenter" under the Map Initialized event of the Map element, but it does nothing. Do you reckon it is the right approach or there's a better way to run a command rigtht after the app initialise. BTW, the "geolocation.auto-recenter" command works as expected under I Want To. My Mobile Designer is still at v5.8, not sure if that matters. 

    0
  • Phil MacIntyre

    Hi Jack,

    I suspect the problem you're probably running into is that the app hasn't managed to receive your user's location quickly enough once the map has loaded in time for the command to work. If the app doesn't have the location, those commands won't work. I know you mentioned wanting to avoid Workflow, but a very simple one might be your solution here. It would simply be a Delay activity and then a Run Command firing the 'geolocation.auto-center' command. You can specify the delay duration in ms. Do a little trial and error, as depending on your device/s, the time it takes for Mobile to get your location can vary. Say maybe start with 3-5 seconds. This will hopefully give the app time enough to get your location before triggering the command.

    That is indeed a fairly old version of Mobile (we're currently on v5.23.1) but the command and event hook you're looking to use have been around for a long time, so it should work. If it wasn't supported, Designer would likely indicate an error as you tried to configure what's in your screenshot.

    Cheers,

    Phil

    0
  • Phil MacIntyre

    Hi again Jack,

    A quick update. I poked through our Developer Center docs and we do have a command version of the Delay activity:

    So you could try chaining 2 commands together in your custom command tied into the mapOnInitilized event. This should accomplish the same thing without needing to involve Workflow at all.

    Cheers,

    Phil

    0

Du måste logga in om du vill lämna en kommentar.