Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 67441

Google Maps API changing an established latitude and longitude

$
0
0

I'm working on a program that takes latitude and longitude and generates nearby locations based on search queries. Everything's working as intended, but I'm at a loss on how I can change the starting coordinates with user coordinates. My initial plan was to have the user enter a lat and lng in the following form:

<form id="mapCenterForm">
    <label for="latitude">lat</label>
    <input type="text" id="lat" name="latitude" placeholder="0.000000">

    <label for="longitude">lng</label>
    <input type="text" id="lng" name="longitude" placeholder="0.000000">
    <br>
    <input type="submit">
</form>

Then used the information entered to change the variables lat, and lng in the script:

  var map;
  var lat= 34.16076;
  var lng= -70.20507;
  var map=new google.maps.LatLng(lat,lng);

      function initMap() {
        // Create the map.
        var SET = {lat, lng};
        map = new google.maps.Map(document.getElementById('map'), {
          center: SET,
          zoom: 10
        });

But I don't know if there's a means of replacing lat and lng that the map loads as a starting point.

Sorry if this is similar to a few other problems posted, I tried using Changing latitude and longitude google maps api for guidance, but it didn't help much for me.


Viewing all articles
Browse latest Browse all 67441

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>