简体   繁体   中英

Insert marker position for Google Map as a url

I want to embed a google map in my react app and I place some location markers there. I use

google-maps-react for this and Maps JavaScript API from google.

Marker in google map takes the position by using longitude and latitude as follows.

<Marker
    name={'Dolores park'}
    position={{lat: 37.759703, lng: -122.428093}} />
  <Marker />

In my app I take the location from the user as a url, as follows

https://goo.gl/maps/4eDhXxvQCqmJnzmT7

My problem is, I want to give the "position" for as a URl. How do I do that? or atleast how do I get the longitude and latitude using the URL mentioned above, inside my code, so that I can paass them to .

You can make a get request to the provided link and parse the coming HTML accordingly. In this way, you can parse latitude and longitude. when requested to your sample link, there is a line with \\"Nawalapitiya\\" [[63356.8217311729,80.4860538,7.0326191]. You should find a way to parse it, then you can use it for every URL.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM