Message Boards Message Boards

GeoGraphics shows incorrect locations with Locator and Dynamic

Posted 6 months ago

If we have the following code:

x = {-63., 45}; GeoGraphics[Locator[x]]

This shows the locator in the correct place. But if we add a dynamic, then the locator ends up in the wrong place, and the graph boundaries are huge.

GeoGraphics[Locator[Dynamic[x]]]

Any suggestions?
Thanks

POSTED BY: Vilis Nams
5 Replies

This seems to work:

Dynamic[GeoGraphics[Locator[GeoPosition[x]], GeoRange -> "World"]]
POSTED BY: Gianluca Gorni
Posted 6 months ago

Your second and third suggestion worked. Thanks.

I'm puzzled why GeoGraphics[Locator[x]] would be treated differently than GeoGraphics[Locator[Dynamic[x]]].

POSTED BY: Vilis Nams

I'm not sure what the precise language design reasons were for the differences in meaning, but I can help clarify how they are different:

In the first case: GeoGraphics[Locator[x]], the kernel does not know that you want to dynamically update the value of x, so, while it updates the coordinates of the Locator, it does not update x.

In the second case GeoGraphics[Locator[Dynamic[x]]], it does update the value of the variable x.

Here is a demonstration to clarify:

DynamicModule[{x1, x2},
 x1 = x2 = {-63.`, 45};
 Grid[{{GeoGraphics[Locator[x1]], Labeled[Dynamic[x1], "x1", Top]},
   {GeoGraphics[Locator[Dynamic[x2]]], 
    Labeled[Dynamic[x2], "x2", Top]}}]
 ]

Dynamic[x] is not evaluated by the Kernel while evaluating GeoGraphics[Locator[Dynamic[x]]. It is only after the graphic is returned to the notebook that x is then evaluated. So the original output is "kinda" equivalent to GeoGraphics[Locator[undefined_symbol_here]], which returns the world map plus a pink box for the invalid Locator position.

POSTED BY: Ian Hojnicki
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract