Random Location Generator: Global Coordinate Creator

Generate random geographic coordinates with a visual map representation. Features include a Generate button, decimal format display, and easy copying.

Random Location Generator

📚

Documentation

Random Location Generator

[... existing content ...]

Visual Representation

To provide a visual context for the generated coordinates, we implement a simple globe icon using SVG. Here's an example of how this can be done:

This SVG creates a simple globe with latitude and longitude lines, and a red dot representing the generated location. The exact position of the dot can be calculated based on the generated coordinates.

[... existing content ...]

Examples

Here are some code examples for generating random coordinates in various programming languages:

1import random
2
3def generate_random_coordinates():
4    latitude = random.uniform(-90, 90)
5    longitude = random.uniform(-180, 180)
6    return latitude, longitude
7
8lat, lon = generate_random_coordinates()
9print(f"{lat:.4f}° {'N' if lat >= 0 else 'S'}, {abs(lon):.4f}° {'E' if lon >= 0 else 'W'}")
10

Copy Button Implementation

To implement the Copy Button functionality, we can use the Clipboard API. Here's a simple JavaScript example:

1function copyToClipboard(text) {
2  navigator.clipboard.writeText(text).then(() => {
3    alert('Coordinates copied to clipboard!');
4  }, (err) => {
5    console.error('Could not copy text: ', err);
6  });
7}
8
9// Usage
10const copyButton = document.getElementById('copyButton');
11copyButton.addEventListener('click', () => {
12  const coordinates = document.getElementById('coordinates').textContent;
13  copyToClipboard(coordinates);
14});
15

This function can be called when the Copy Button is clicked, passing the generated coordinates as the text to be copied.

[... rest of the existing content ...]