-1

I've got a Google Maps object with a Fusion Tables layer on it. I'm trying to make it so that when you click the FT layer, you'll see a marker where you click. I've written code that gets the latitude and longitude of where you click. I've also written code that's supposed to set up the location of the marker, but it doesn't work.

See below...

google.maps.event.addListener(layer,'click',function(e){
    var clickedLatLng = {
        lat: e['latLng']['B'],
        lng: e['latLng']['k']
    }

    var myLatLng = new google.maps.LatLng(clickedLatLng['lat'],clickedLatLng['lng'])

    var marker = new google.maps.Marker({
        position: myLatLng,
        map: gmap
    });

    marker.setMap(gmap);
});

How do I make it so that the marker appears?

Generic_User_ID
  • 1,067
  • 2
  • 13
  • 16
  • possible duplicate of [How do I make this script fire when I click a Fusion Tables layer?](http://stackoverflow.com/questions/25626857/how-do-i-make-this-script-fire-when-i-click-a-fusion-tables-layer) – geocodezip Sep 03 '14 at 00:25

1 Answers1

1

Your code (currently) works, but with a undesired result.

The properties e['latLng']['B'] and e['latLng']['k'] are not documented, you should not try to access them because the names of the properties(B and k ) are not stable(see Something happened to my google map api script ).

You've switched latitude and longitude, the marker will appear, but not at the clicked place(zoom-out the map to 0 and you'll see him somewhere)

There is no need to create a new LatLng, e.latLng is already a google.maps.LatLng, you may use it directly:

  google.maps.event.addListener(layer,'click',function(e){

    new google.maps.Marker({
        position:e.latLng,
        map: this.getMap()
    });

  });
Community
  • 1
  • 1
Dr.Molle
  • 116,463
  • 16
  • 195
  • 201