开发者

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 s开发者_如何学Pythonimilar to this, so I could pass user input values e.g. numbers to my javascript for further use?


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

I put together an example on jsfiddle.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜