Mapping to unique nearest point In my class, we showed that if $B$ is closed in $\mathbb{R}$ and $A\subseteq\mathbb{R}$ and every $x\in A$ has the unique nearest point $f\left(x\right)$ of $B$, then $x\mapsto f\left(x\right)$ is continuous.
My professor asked if we could find an arbitrary metric space $X$ (not necessarily with $X=\mathbb{R}$) where $A$ and $B$ (with $B$ not necessarily having to be closed now) have this same unique nearest point property, but $f$ is no longer continuous.
I've been thinking about it for a couple of days now, but I haven't come up with any examples. If anyone could provide an example, I would greatly appreciate it.
 A: Notation: To avoid confusion between intervals and ordered pairs, $\langle a,b\rangle$ is an ordered pair. 
With the usual metric on $\Bbb R^2,$ let $A=[0,1]\times \{0\}$ and $B= ([0,1)\times \{1\})\cup \{\langle  2,0\rangle \}. $ Let $X=A\cup B.$ 
If $0\leq t<1$ then $f(\langle t,0\rangle)=\langle t,1\rangle.$ 
But $f(\langle 1,0\rangle)=\langle 2,0 \rangle.$
So $f(x)$ is discontinuous at $x=\langle 1,0 \rangle.$ (See footnote). Note that $A$ and $B$ are closed in $X$.
The tricky part of constructing an example is that in any metric space $(X,d),$ if $X\supset B\ne \phi$ and $g(x)=\inf \{d(x,y):y\in B\}$ then $g:X\to \Bbb R$ $is$ continuous. 
Footnote. The sequence  $(\;f(\langle 1-1/n,0 \rangle)\;)_{n\in \Bbb N}$ does not converge to $f(\langle 1,0\rangle).$
A: This is to provide an answer using an example I provided in the comments.
Let $X=\mathbb{R}^{2}$ with the standard Euclidean metric, and let $A=\left\{\left(x,0\right):x\in\mathbb{R}\right\}$ and $B=\left\{\left(x,1\right):x\ge0\right\}\cup\left\{\left(x,-1\right):x<0\right\}$. If $x\ge0$, then the only nearest point in $\mathbb{R}^{2}$ is obviously $\left(x,1\right)$. If $x<0$, then the only nearest point is obviously $\left(x,-1\right)$. Take the sequence $x_{n}=-\frac{1}{n}$. This obviously converges to $0$, but
$$\lim\limits_{n\rightarrow\infty}\left(f\left(x_{n}\right)\right)=\lim\limits_{n\rightarrow\infty}\left(f\left(-\frac{1}{n}\right)\right)$$
$$\lim\limits_{n\rightarrow\infty}\left(\left(-\frac{1}{n},-1\right)\right)=\left(0,-1\right)\ne f\left(0\right)=\left(0,1\right).$$
Thus, $f$ is discontinuous at $x=0$.
A: $A = \{1\}\times\mathbb{R};\  B = \{0\}\times\bigl([-1,0) \cup [1,2]\bigr)$.
