Question

I would like to ask how can I assign the input(lat,lng) of a user as the position for the marker that I want to create in the specified input(lat,lng)???

     function dropmarker()
     {
  map.setOptions({center:new google.maps.LatLng(prompt("Latitude"),prompt("Longitude:"))});
   var blue = prompt ("please chose a color");
   if(blue !==null)
    {

  var marker = new google.maps.Marker({
  position:  ?????
  map: map,
  title: 'blue marker',
  icon:'blue.png'
  });
   }
Was it helpful?

Solution

You can try, as the position is equal to the center of the map :

position:  map.getCenter(),

Or, i think a proper way, put prompt results into variables :

var lat = prompt("Latitude");
var lng = prompt("Longitude:");
var currentLatLng = new google.maps.LatLng(lat,lng);

map.setOptions({center:currentLatLng});

and then

position : currentLatLng,
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top