Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9066749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:47:29+00:00 2026-06-16T16:47:29+00:00

I want is to get the coordinates from a string (grabbed from the src

  • 0

I want is to get the coordinates from a string (grabbed from the src of a Google Maps img). Below is a poor try of mine with regex that doesn’t work.

So, what is the best way to do this? With regex? In that case how should be composed?

$string = "//maps.google.com/maps/api/staticmap?sensor=false&center=56.393906,16.066206&zoom=12&size=344x170&language=sv&markers=56.393906,16.066206&maptype=roadmap&scale=1";

$matches = array();
preg_match('/center=(.*?)\zoom/s', $string, $matches);

... ?

Wanted end result:

$coordiates = (
    [0] = '56.393906',
    [1] = '16.066206'
);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T16:47:30+00:00Added an answer on June 16, 2026 at 4:47 pm

    You shouldn’t use a regex for something like this as it would be slower and more prone to break if URL changes. PHP has built in functions already for such a thing. Use parse_url() and parse_str() to easily accomplish it.

    $string = "//maps.google.com/maps/api/staticmap?sensor=false&center=56.393906,16.066206&zoom=12&size=344x170&language=sv&markers=56.393906,16.066206&maptype=roadmap&scale=1";
    
    parse_str(parse_url($string, PHP_URL_QUERY), $vars);
    
    print_r($vars);
    

    Outputs:

    Array
    (
        [sensor] => false
        [center] => 56.393906,16.066206
        [zoom] => 12
        [size] => 344x170
        [language] => sv
        [markers] => 56.393906,16.066206
        [maptype] => roadmap
        [scale] => 1
    )
    

    So to get your coordinates just do:

    $coords = explode(',', $vars['center']);
    print_r($coords);
    
    // Outputs:
    Array
    (
        [0] => 56.393906
        [1] => 16.066206
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to get 100 and example from this string ?connect:100/username:example/ I searched in
i want to get the GPS coordinates from iphone and send these GPS coordinates
I want this Ellipse to get its coordinates from its corresponding BallViewModel, and to
I want get as much as possible from Redis + Hiredis + libevent. I'm
What I want: get a xml from the AppData to use What I code
Basically I want get data I already have accessed from javascript and passing it
I am trying to get the coordinates from a touch but I can't figure
I have a class extends ViewGroup and want to get every MotionEvent from it.
I want to show some points/coordinates retrieved from an SQLite databse. The weird thing
I want to get the center coordinates of the map while the user is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.