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

使用VB.NET提取Google Maps URL经纬度并填入文本框

Extract Coordinates from Google Maps URL and Populate Text Boxes

Great question! Let's break down how to pull those latitude and longitude values from your Google Maps URL and get them into TextBox1 and TextBox2. The coordinates you need are tucked right after the @ symbol in the URL, formatted as @[latitude],[longitude],[zoom]z.... Here are two solid methods to do this:

Regex is the most reliable approach here because it can directly capture the numeric values even if other parts of the URL shift slightly (like different zoom levels or extra parameters). It also handles negative coordinates seamlessly if you ever need those.

Example in C# (Windows Forms)

If you're working with a Windows Forms application, this code will do the trick:

using System.Text.RegularExpressions;

// Your Google Maps URL
string mapsUrl = "https://www.google.com/maps/place/Aleem+Iqbal+SEO/@31.888433,73.263572,17z/data=!3m1!4b1!4m5!3m4!1s0x39221cb7e4154211:0x9cf2bb941cace556!8m2!3d31.888433!4d73.2657607";

// Regex pattern to capture latitude and longitude (supports negative values too)
string coordPattern = @"@(-?\d+\.\d+),(-?\d+\.\d+)";
Match coordMatch = Regex.Match(mapsUrl, coordPattern);

if (coordMatch.Success)
{
    // Populate TextBox1 with latitude
    TextBox1.Text = coordMatch.Groups[1].Value;
    // Populate TextBox2 with longitude
    TextBox2.Text = coordMatch.Groups[2].Value;
}
else
{
    // Fallback if coordinates aren't found in the URL
    TextBox1.Text = "Latitude not found";
    TextBox2.Text = "Longitude not found";
}

Example in JavaScript (Web Applications)

For a web-based project with HTML text inputs, use this snippet:

const mapsUrl = "https://www.google.com/maps/place/Aleem+Iqbal+SEO/@31.888433,73.263572,17z/data=!3m1!4b1!4m5!3m4!1s0x39221cb7e4154211:0x9cf2bb941cace556!8m2!3d31.888433!4d73.2657607";
const coordRegex = /@(-?\d+\.\d+),(-?\d+\.\d+)/;
const matchResult = mapsUrl.match(coordRegex);

if (matchResult) {
    document.getElementById("TextBox1").value = matchResult[1];
    document.getElementById("TextBox2").value = matchResult[2];
} else {
    document.getElementById("TextBox1").value = "Latitude not found";
    document.getElementById("TextBox2").value = "Longitude not found";
}

Method 2: String Splitting (Simpler, Less Flexible)

If you're certain the URL structure won't change, string splitting is a quick and easy alternative. Just note that it's less resilient if Google tweaks their URL format down the line.

C# Example

string mapsUrl = "https://www.google.com/maps/place/Aleem+Iqbal+SEO/@31.888433,73.263572,17z/data=!3m1!4b1!4m5!3m4!1s0x39221cb7e4154211:0x9cf2bb941cace556!8m2!3d31.888433!4d73.2657607";

// Split the URL at the "@" to isolate the coordinate section
string[] afterAt = mapsUrl.Split('@');
if (afterAt.Length > 1)
{
    // Split the coordinate section by commas to get individual values
    string[] coords = afterAt[1].Split(',');
    if (coords.Length >= 2)
    {
        TextBox1.Text = coords[0];
        TextBox2.Text = coords[1];
    }
}

JavaScript Example

const mapsUrl = "https://www.google.com/maps/place/Aleem+Iqbal+SEO/@31.888433,73.263572,17z/data=!3m1!4b1!4m5!3m4!1s0x39221cb7e4154211:0x9cf2bb941cace556!8m2!3d31.888433!4d73.2657607";
const urlParts = mapsUrl.split('@');
if (urlParts.length > 1) {
    const coordParts = urlParts[1].split(',');
    if (coordParts.length >= 2) {
        document.getElementById("TextBox1").value = coordParts[0];
        document.getElementById("TextBox2").value = coordParts[1];
    }
}

Both methods will correctly extract 31.888433 into TextBox1 and 73.263572 into TextBox2. I recommend the regex approach for its flexibility, but the splitting method works great if you're dealing with a consistent URL format.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.25 02:32:55