You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用Python通过坐标调用并显示谷歌地球卫星图像

Hey there, sorry you’ve been banging your head on this for a month—let’s walk through two reliable ways to pull and display Google Earth-style satellite imagery using Python with your target coordinates. I’ve used both approaches for different projects, so they should work if you follow the steps carefully.

方法1:使用Google Maps Static API(快速获取卫星图)

This is the simplest way to get a satellite image matching what you’d see in Google Earth, since it pulls directly from the same imagery source.

前提准备

  • You’ll need a Google Cloud API key, and you have to enable the Maps Static API in your Google Cloud console (there’s a free tier for low usage, but watch out for overages).

代码示例

import requests
from PIL import Image
import matplotlib.pyplot as plt

# Replace with your own Google Cloud API key
API_KEY = "your_actual_api_key_here"
# Your target coordinates (latitude, longitude) — example uses San Francisco
target_lat, target_lon = 37.7749, -122.4194
# Adjust zoom (1 = global view, 20 = street-level detail; 14-18 works great for city areas)
zoom_level = 15
# Image size (max 640x640 for free tier)
img_size = "600x600"

# Build the request URL for satellite imagery
satellite_url = f"https://maps.googleapis.com/maps/api/staticmap?center={target_lat},{target_lon}&zoom={zoom_level}&size={img_size}&maptype=satellite&key={API_KEY}"

# Download the image
response = requests.get(satellite_url)
with open("satellite_shot.jpg", "wb") as img_file:
    img_file.write(response.content)

# Display the image
sat_img = Image.open("satellite_shot.jpg")
plt.imshow(sat_img)
plt.axis('off')  # Hide messy axes
plt.show()

关键注意点

  • The maptype=satellite parameter is what triggers the Google Earth-style satellite layer.
  • Double-check your API key is enabled for Maps Static API—if you get an error, this is the first thing to verify.
方法2:使用Google Earth Engine(适合批量/历史影像)

If you need access to historical satellite data or want to process imagery beyond just viewing, Earth Engine is the way to go. It’s Google’s platform for geospatial analysis, and it uses the same underlying imagery as Google Earth.

前提准备

  1. Sign up for a Google Earth Engine account (free for non-commercial use).
  2. Install the library: pip install earthengine-api
  3. Authenticate your account by running earthengine authenticate in your terminal (follow the prompts to log in).

代码示例

import ee
import requests
from PIL import Image
import matplotlib.pyplot as plt

# Initialize Earth Engine
ee.Initialize()

# Your target coordinates (note: Earth Engine uses [longitude, latitude] order!)
target_lon, target_lat = -122.4194, 37.7749
# Create a 1km x 1km area around your point (adjust buffer size as needed)
target_region = ee.Geometry.Point([target_lon, target_lat]).buffer(500).bounds()

# Pull the latest cloud-free Landsat 8 image (matches Google Earth's default satellite layer)
satellite_collection = ee.ImageCollection('LANDSAT/LC08/C02/T1_TOA') \
    .filterBounds(target_region) \
    .sort('CLOUD_COVER') \
    .first()  # Grab the image with the least cloud cover

# Select RGB bands to get a true-color image
rgb_image = satellite_collection.select(['B4', 'B3', 'B2'])

# Generate a thumbnail URL and download the image
thumb_url = rgb_image.getThumbURL({
    'region': target_region,
    'dimensions': 600,
    'format': 'jpg',
    'min': 0,
    'max': 0.3  # Adjust these values to match Google Earth's brightness
})

response = requests.get(thumb_url)
with open("ee_satellite.jpg", "wb") as img_file:
    img_file.write(response.content)

# Display the image
ee_img = Image.open("ee_satellite.jpg")
plt.imshow(ee_img)
plt.axis('off')
plt.show()

关键注意点

  • Earth Engine uses longitude first, latitude second for coordinates—this is a super common gotcha, so don’t mix them up!
  • If you want imagery that looks exactly like Google Earth’s default view, try using the GOOGLE/SATELLITE image collection instead of Landsat (it’s a static mosaic, so less up-to-date but matches the UI).
Quick Troubleshooting Tips
  • If your API request fails: Check that your key is active, you’ve enabled the correct API, and you haven’t exceeded your quota.
  • Earth Engine authentication issues: Re-run earthengine authenticate and make sure you’re using the same Google account as your Earth Engine registration.
  • Blurry images: Crank up the zoom level (for Static API) or adjust the dimensions parameter (for Earth Engine).

内容的提问来源于stack exchange,提问作者Akash

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 21:27:49