October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
Cupertino desk4 min

Turn Latitude and Longitude into Google Maps, Apple Maps, or OpenStreetMap Links with JavaScript

Use JavaScript’s URL APIs to turn decimal latitude and longitude into working Google Maps, Apple Maps, or OpenStreetMap links.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To open decimal coordinates in a map, build a service-specific HTTPS URL with latitude first and longitude second, then place it in a regular link. Google Maps needs api=1 and a query parameter; Apple Maps accepts a coordinate pair; OpenStreetMap can use marker parameters and a map fragment for its center and zoom. JavaScript’s URL and URLSearchParams handle query-string encoding for you.

Validate the coordinates before making a link

Use decimal degrees in latitude,longitude order. Keep negative signs: a negative latitude is south of the equator, and a negative longitude is west of the prime meridian. For example, 37.422 and -122.084 represent latitude 37.422 and longitude -122.084.

As an Amazon Associate I earn from qualifying purchases.

Check that both values are finite numbers and within geographic bounds before building a URL:

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Latitude: -90 through 90.
  • Longitude: -180 through 180.
function validateCoordinates(lat, lon) {
  if (!Number.isFinite(lat) || !Number.isFinite(lon)) {
    throw new TypeError("Latitude and longitude must be finite numbers.");
  }
  if (lat < -90 || lat > 90) {
    throw new RangeError("Latitude must be between -90 and 90.");
  }
  if (lon < -180 || lon > 180) {
    throw new RangeError("Longitude must be between -180 and 180.");
  }
}

These checks prevent invalid coordinate values; they are geographic bounds, not a guarantee that a mapping service has a named place or feature at that point.

#1 Best Overall
Sale
Garmin Drive™ 53 GPS Navigator
  • Bright, high-resolution 5” glass capacitive touchscreen display lets you easily view your route
  • Get more situational awareness with alerts for school zones, speed changes, sharp curves and more
  • View food, fuel and rest areas along your active route, and see upcoming cities and milestones
  • View Tripadvisor traveler ratings for top-rated restaurants, hotels and attractions to help you make the most of road trips
  • Directory of U.S. national parks simplifies navigation to entrances, visitor centers and landmarks within the parks

Build a Google Maps coordinate link

For a coordinate pin, use Google’s Maps search URL with api=1 and a comma-separated latitude,longitude query. Google says api=1 is required for every Maps URL request; without it, the parameters are ignored and the default map opens. Its documentation also says to encode URLs properly and sets a 2,048-character limit per request. See Google Maps URLs: Get Started.

function googleMapsUrl(lat, lon) {
  validateCoordinates(lat, lon);
  const url = new URL("https://www.google.com/maps/search/");
  url.searchParams.set("api", "1");
  url.searchParams.set("query", `${lat},${lon}`);
  return url.toString();
}

const link = googleMapsUrl(37.422, -122.084);
// https://www.google.com/maps/search/?api=1&query=37.422%2C-122.084

A coordinate-only search places a pin but does not provide additional place information. If the link must identify a particular establishment, Google supports adding a known query_place_id alongside the query.

Rank #2
Sale
Garmin DriveSmart 66, 6-inch Car GPS Navigator with Bright, Crisp High-Resolution Maps and Garmin Voice Assist
  • 6” high-resolution navigator includes map updates of North America
  • Hands-free calling when paired with your compatible smartphone with BLUETOOTH technology and convenient Garmin voice assist lets you ask for directions to places you want to go
  • Road trip–ready features include the HISTORY database of notable sites, a U.S. national parks directory, Tripadvisor traveler ratings and millions of Foursquare POIs
  • Driver alerts for things such as school zones, sharp curves and speed changes help encourage safer driving and increase situational awareness
  • Access live traffic, fuel prices, parking, weather and smart notifications when you pair this navigator with your compatible smartphone running the Garmin Drive app

Use a directions URL when the goal is a route

A search link and a directions link do different things. To request directions to a coordinate, use destination instead of query; Google allows the origin to be omitted.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
function googleDirectionsUrl(lat, lon) {
  validateCoordinates(lat, lon);
  const url = new URL("https://www.google.com/maps/dir/");
  url.searchParams.set("api", "1");
  url.searchParams.set("destination", `${lat},${lon}`);
  return url.toString();
}

With no origin supplied, Google may use a relevant current location or show a blank directions form. The exact result depends on the context in which the URL is opened. The parameter format is documented in Google’s Maps URLs guide.

Rank #3
Garmin 010-02256-00 eTrex 22x, Rugged Handheld GPS Navigator, Black/Navy
  • Explore confidently with the reliable handheld GPS
  • 2.2” sunlight-readable color display with 240 x 320 display pixels for improved readability
  • Preloaded with Topo Active maps with routable roads and trails for cycling and hiking
  • Support for GPS and GLONASS satellite systems allows for tracking in more challenging environments than GPS alone
  • 8 GB of internal memory for map downloads plus a micro SD card slot

Build an Apple Maps coordinate link

Apple’s unified Maps URL documentation describes coordinate as a comma-separated latitude,longitude pair and supports coordinate-based map display and directions. The archived Map Links reference documents the ll parameter for a latitude,longitude pair. This map-display example uses ll:

function appleMapsUrl(lat, lon) {
  validateCoordinates(lat, lon);
  const url = new URL("https://maps.apple.com/");
  url.searchParams.set("ll", `${lat},${lon}`);
  return url.toString();
}

const link = appleMapsUrl(37.422, -122.084);

Apple’s unified URL documentation also describes coordinate-based directions using source and destination, either of which may be a coordinate. Consult Apple’s unified Maps URLs documentation and archived Map Links reference for the URL formats.

Rank #4
Sale
Garmin DriveSmart 86, 8-inch Car GPS Navigator with Bright, Crisp High-Resolution Maps and Garmin Voice Assist
  • 8” navigator with high-resolution, dual-orientation display and map updates of North America .Special Feature:Large Display; Voice Assist; Hands-Free Calling; Live Traffic and Weather; Traffic Cams and Parking; Smart Notifications,Driver Alerts; Tripadvisor; National Parks Directory; Find Places by Name; Garmin Real Directions Feature.
  • Hands-free calling when paired with your compatible smartphone with BLUETOOTH technology and convenient Garmin voice assist lets you ask for directions to places you want to go
  • Road trip–ready features include the HISTORY database of notable sites, a U.S. national parks directory, Tripadvisor traveler ratings and millions of Foursquare POIs
  • Driver alerts for things such as school zones, sharp curves and speed changes help encourage safer driving and increase situational awareness
  • Access live traffic, fuel prices, weather, parking and smart notifications when you pair this navigator with your compatible smartphone running the Garmin Drive app
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Build an OpenStreetMap link with a marker and zoom

OpenStreetMap’s website can center the map with a URL fragment in the form #map=ZOOM/LAT/LON. The mlat and mlon query parameters set a red marker. Use the same coordinates for the marker and the center so that the marker is in the visible map area.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
function openStreetMapUrl(lat, lon, zoom = 16) {
  validateCoordinates(lat, lon);
  if (!Number.isInteger(zoom) || zoom < 0) {
    throw new RangeError("Zoom must be a non-negative integer.");
  }

  const url = new URL("https://www.openstreetmap.org/");
  url.searchParams.set("mlat", String(lat));
  url.searchParams.set("mlon", String(lon));
  url.hash = `map=${zoom}/${lat}/${lon}`;
  return url.toString();
}

The fragment is separate from the query string, so the code sets it directly and retains its documented slash separators. OpenStreetMap’s Browsing wiki documents this format and cautions that URL parameter support may change. It also notes that a marker can sit outside the visible map when the map center differs from the marker position.

Best Value
Sale
Garmin Drive™ 53 GPS Navigator, High-Resolution Touchscreen, Simple On-Screen Menus and Easy-to-See Maps, Driver Alerts (Renewed)
  • Bright, high-resolution 5” glass capacitive touchscreen display lets you easily view your route
  • Get more situational awareness with alerts for school zones, speed changes, sharp curves and more
  • View food, fuel and rest areas along your active route, and see upcoming cities and milestones
  • View Tripadvisor traveler ratings for top-rated restaurants, hotels and attractions to help you make the most of road trips
  • Directory of U.S. national parks simplifies navigation to entrances, visitor centers and landmarks within the parks

Offer the links as ordinary anchors

Once the URL is built, assign it to an HTTPS anchor. This gives the browser a standard link to handle rather than assuming a particular app is installed.

const lat = 37.422;
const lon = -122.084;

googleLink.href = googleMapsUrl(lat, lon);
appleLink.href = appleMapsUrl(lat, lon);
osmLink.href = openStreetMapUrl(lat, lon, 16);

In HTML, the resulting links can be rendered as <a href="...">Open in Google Maps</a> and corresponding Apple Maps and OpenStreetMap anchors. Do not promise that a link will always launch a native app: browser, operating system, user settings, and installed apps affect whether the destination opens in a browser or app. Google documents custom URL schemes for app-specific iOS behavior, but recommends checking app availability; for a web page, its universal HTTPS Maps URLs have broader platform handling. See Google Maps URL Scheme for iOS.

Quick Recap

SaleBestseller No. 1
Garmin Drive™ 53 GPS Navigator
Garmin Drive™ 53 GPS Navigator
Includes detailed map updates of the North America
$141.98
SaleBestseller No. 2
Garmin DriveSmart 66, 6-inch Car GPS Navigator with Bright, Crisp High-Resolution Maps and Garmin Voice Assist
Garmin DriveSmart 66, 6-inch Car GPS Navigator with Bright, Crisp High-Resolution Maps and Garmin Voice Assist
6” high-resolution navigator includes map updates of North America; Built-in Wi-Fi connectivity allows easy map and software updates without a computer
$199.99
Bestseller No. 3
Garmin 010-02256-00 eTrex 22x, Rugged Handheld GPS Navigator, Black/Navy
Garmin 010-02256-00 eTrex 22x, Rugged Handheld GPS Navigator, Black/Navy
Explore confidently with the reliable handheld GPS; Preloaded with Topo Active maps with routable roads and trails for cycling and hiking
$199.99
SaleBestseller No. 4
Garmin DriveSmart 86, 8-inch Car GPS Navigator with Bright, Crisp High-Resolution Maps and Garmin Voice Assist
Garmin DriveSmart 86, 8-inch Car GPS Navigator with Bright, Crisp High-Resolution Maps and Garmin Voice Assist
Built-in Wi-Fi connectivity allows easy map and software updates without a computer
$281.76

Coordinate order and link behavior at a glance

Service Coordinate link format What it does
Google Maps https://www.google.com/maps/search/?api=1&query=LAT%2CLON Searches the coordinate and places a pin.
Apple Maps https://maps.apple.com/?ll=LAT%2CLON Opens a map at the coordinate.
OpenStreetMap https://www.openstreetmap.org/?mlat=LAT&mlon=LON#map=ZOOM/LAT/LON Sets a red marker and map center with a chosen zoom.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.