1. A device-to-device (D2D) transmission distance obtaining method, comprising:receiving, by a second device from a first device, transmit power information that indicates a transmit power at which the first device sends data to the second device, wherein the transmit power information is included in a header of Media Access Control (MAC) layer communication data from the first device, and wherein the transmit power is represented as a distance value or a distance threshold range;
obtaining, by the second device, receive power information that indicates a receive power at which the second device receives the data from the first device; and
obtaining, by the second device, a distance between the second device and the first device according to the receive power and the transmit power, wherein the distance between the second device and the first device is calculated by:
subtracting the receive power from the transmit power to obtain a power difference; and
dividing the power difference by a power loss per unit of distance to calculate the distance.