user494461
user494461

Reputation:

how to get a user input in google maps using custom controls?

I have custom controls on my map with this tutorial http://code.google.com/apis/maps/documentation/javascript/controls.html#CustomDrawing

how can I create input boxes with something similar to this, so I could pass user input values e.g. numbers to my javascript for further use?

Upvotes: 3

Views: 6330

Answers (2)

Wolfram
Wolfram

Reputation: 8052

It isn't that different to add inputs, buttons or labels instead of divs.

I put together an example on jsfiddle.

Upvotes: 2

NT3RP
NT3RP

Reputation: 15370

If you want to create custom controls that happen to be input buttons, it works in a manner very similar to the way in the link you've posted. Instead of a div, you'll need to make an input.

The code would look something like this:

//create your control HTML
var controlDiv = document.createElement('DIV');

var controlInput = document.createElement('INPUT');
controlInput.name = "inputName";
controlInput.type = "text";
controlDiv.appendChild(controlInput);

//create your control javascript (e.g. any handlers that you need)
var myControl = MyControl(controlDiv)

//add the control to your map
map.controls[google.maps.ControlPosition.TOP_RIGHT].push(controlDiv);

As you've already mentioned, the tutorial should cover most of the issues you're encountering, you just need to ensure that you create an input element and get values from that.

Upvotes: 1

Related Questions