Union of metric spaces Is the union of two metric spaces a metric space?
I tried it but could't define a suitable metric on intersection. Can somebody help me to understand it?

Since you are explicitly considering overlapping underlying sets, you have to explicitly specify what you want for the intersection. The problem is that if you have arbitrary metrics, then for $x,y\in X_1\cap X_2$ you may have $d_1(x,y)\ne d_2(x,y)$.
Note that I'm consistently assuming non-empty intersection in this post. If the intersection is empty, the answer by Dimiter Skordev gives a viable metric.
Now one way to proceed is to demand that the metrics are compatible, that is to demand that for points in the intersection the two metrics actually agree. In that case, it is easy to build a common metric:
$$d(x,y) = \begin{cases}
d_1(x,y) & x,y\in X_1\\
d_2(x,y) & x,y\in X_2\\
\inf\limits_{a\in X_1\cap X_2} d_1(x,a)+d_2(a,y) & x\in X_1, y\in X_2\\
\inf\limits_{a\in X_1\cap X_2} d_2(x,a)+d_1(a,y) & x\in X_2, y\in X_1
\end{cases}$$
If the metrics are not compatible in that way, you have to specify what you want to preserve from the new metric. One possibility would be that the new metric should be upper-bounded by each of the given metrics. This can be ensured by the following construction:
Let's define a “hopping path” $H$ from $a$ to $b$ as finite sequence $(x_0,x_1,\ldots,x_n)$ with the following properties:


*

*$x_0=x$, $x_n=y$.

*$x_k$ and $x_{k+1}$ are both in $X_1$ or both in $X_2$.
Now we can define the “hop distance” $h$ between two subsequent points as follows (note that this is not yet the metric!):
$$h(x_k,x_{k+1}) = \begin{cases}
\min\{d_1(x_k,x_{k+1}),d_2(x_k,x_{k+1})\} & x_1,x_2\in X_1\cap X_2\\
d_1(x_k,x_{k+1}) & \text{one of the points is only in $X_1$}\\
d_2(x_k,x_{k+1} & \text{one of the points is only in $X_2$}
\end{cases}$$
We then define the “hopping length” of a hopping path as the sum of its hopping distances:
$$l(H) = \sum_{k=0}^{n-1} h(x_k,x_{k+1})$$
Now we can define the metric $d(a,b)$ as the infimum of the hopping lengths of all hopping paths from $a$ to $b$.
