Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.3k views
in Technique[技术] by (71.8m points)

How can I get the information from "coordinates" and save it in a PHP variable?

I'm looking for some ways but I'm having a lot of difficulty ... I just need the information that is in "coordinates" and put it in a PHP

<script>
        mapboxgl.accessToken = 'MY_KEY :3';
    
        var client = new MapboxClient(mapboxgl.accessToken);
    
        var address = 'white house';
        var test = client.geocodeForward(address, function(err, data, res) {
    
    
          var coordinates = data.features[0].center;
 
          document.write(coordinates);
          //console.log(coordinates);
     
          var map = new mapboxgl.Map({
            container: 'map',
            style: 'mapbox://styles/mapbox/streets-v10',
            center: coordinates,
            zoom: 14
          });
          new mapboxgl.Marker()
            .setLngLat(coordinates)
            .addTo(map);
        });
    
      </script>
    </head>  
    <body>
      <div id='map'></div>
    </body>

A very simple example is this

<?php $coord = 'coordinates'; ?>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I do not know what you want to calculate but there are all kinds of API's that you can use with php.

e.g. convert an address to the coordinates..

MAPBOX API for Geocoding: https://docs.mapbox.com/help/how-mapbox-works/geocoding/

Google Maps is an alternative solution: https://developers.google.com/maps/documentation/

https://developers.google.com/maps/documentation/geocoding/overview


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...