InvalidValueError:不是HTMLInputElement的实例 [英] InvalidValueError: not an instance of HTMLInputElement
问题描述
我实现了一张地图。用户可以搜索谷歌地点并为其添加标记。有一个文本框。或者用户可以点击地图将标记放置到他要查找的地方或拖动标记。
代码保持不变。设计改变了。输入字段的ID和名称也相同。没有改变JS代码。但这件事情没有奏效。
以下是网站
Google地图产生错误。
InvalidValueError:不是HTMLInputElement的实例
我尝试了解决方案此处
但错误仍然存在。
可能的原因是什么?
以下是代码:
var map;
var marker;
var latLngC;
函数initialize()
{
latLngC = new google.maps.LatLng(14.5800,121.0000);
var mapOptions = {
center:latLngC,
zoom:12,
mapTypeId:google.maps.MapTypeId.ROADMAP,
};
map = new google.maps.Map(document.getElementById('source_map'),
mapOptions);
var marker = new google.maps.Marker({
position:latLngC,
map:map,
draggable:true
});
google.maps.event.addListener(marker,'dragend',function(x)
{
document.getElementById('src_lat')。value = x.latLng。 lat();
document.getElementById('src_long')。value = x.latLng.lng();
document.getElementById('pickup location')。innerHTML = x.latLng.lat()+ ','+ x.latLng.lng();
var geocoder = new google.maps.Geocoder;
var infowindow = new google.maps.InfoWindow;
geocodeLatLng(geocoder,map, infowindow,x.latLng.lat(),x.latLng.lng(),'source_point');
});
//获取坐标,地址单击地图中的某个位置(源地图)
//通过Sajeev
google.maps.event.addListener(地图,'点击',函数(x)
{
document.getElementById('src_lat')。value = x.latLng.lat();
document.getElementById('src_long')。value = x.latLng .lng();
document.getElementById('pickup location')。innerHTML = x.latLng.lat()+','+ x.latLng.lng();
var geocoder = new google。 maps.Geocoder;
var infowindow = new google.maps.InfoWindow;
geocodeLatLng(geocoder,map,infowindow,x.latLng.lat(),x.latLng.lng(),'source_point') ;
});
//点击地图时添加标记
//google.maps.event.addDomListener(map,'click',addMarker);
google.maps.event.addDomListener(map,'click',function(){addMarker(map);});
var places1 = new google.maps.places.Autocomplete(document.getElementById('source_point'));
google.maps.event.addListener(places1,'place_changed',function(){
var place1 = places1.getPlace();
var src_addr = place1.formatted_address;
var src_lat = place1.geometry.location.lat();
var src_long = place1.geometry.location.lng();
var mesg1 =地址:+ src_addr;
mesg1 + =\\\
Latitude:+ src_lat;
mesg1 + =\\\
Longitude:+ src_long;
// alert(mesg1);
document.getElementById('src_lat')。value = src_lat;
document.getElementById('src_long')。value = src_long;
document.getElementById('pickup location')。innerHTML = src_lat +' ,'+ src_long;
});
//在地方添加标记更改
//google.maps.event.addDomListener(places1,'place_changed',addMarker);
google.maps.event.addDomListener(places1,'place_changed',function(){addMarker(map);});
google.maps.event.addDomListener(window,'resize',initialize);
google.maps.event.addDomListener(window,'load',initialize);
我的HTML代码如下所示:
< form role =formid =frm_sourcename =frm_sourcemethod =POSTaction =index_action.php>
< div class =form-group>
< label for =source_point>< h2> Pickup Address< / h2>< / label>
< / div>
< div class =form-group>
< label for =pickup位置>< h3> GPS坐标< / h3>< / label>
< hr>
< p id =pickup位置>< / p>
< / div>
< div class =form-group>
< input type =hiddenid =src_latname =src_latplaceholder =latitude>
< input type =hiddenid =src_longname =src_longplaceholder =longitude>
< / div>
< / form>
Google Map
< div id =source_map>< / div>
您的字段为 TEXTAREA
,并且从上次更新中,Google地图自动完成功能现在仅支持 window.HTMLInputElement(INPUT标记)
: - (
FYI, I'm not a JavaScript Ninja but felt like I'll become one when I did a lot of things based on Google Maps recently.
I implemented a map. User can search for google places and place a marker for it. there's a text box for that. Or user can click on the map to place a marker to the place he's looking for or drag the marker.
Code remains the same. Design changed. Input field's id and name also same. No change to JS code. But this thing ain't working.
Here's the website
Google map is producing an error.
InvalidValueError: not an instance of HTMLInputElement
I tried solution given here But error still remains.
What could be the possible reason?
Here's the code:
var map;
var marker;
var latLngC;
function initialize()
{
latLngC = new google.maps.LatLng(14.5800, 121.0000);
var mapOptions = {
center: latLngC,
zoom: 12,
mapTypeId: google.maps.MapTypeId.ROADMAP,
};
map = new google.maps.Map(document.getElementById('source_map'),
mapOptions);
var marker = new google.maps.Marker({
position: latLngC,
map: map,
draggable: true
});
google.maps.event.addListener(marker, 'dragend', function (x)
{
document.getElementById('src_lat').value = x.latLng.lat();
document.getElementById('src_long').value = x.latLng.lng();
document.getElementById('pickup_location').innerHTML = x.latLng.lat()+' , '+x.latLng.lng();
var geocoder = new google.maps.Geocoder;
var infowindow = new google.maps.InfoWindow;
geocodeLatLng(geocoder, map, infowindow,x.latLng.lat(),x.latLng.lng(),'source_point');
});
//Get coordinates,address Upon clicking a location in map (Source Map)
//By Sajeev
google.maps.event.addListener(map, 'click', function(x)
{
document.getElementById('src_lat').value = x.latLng.lat();
document.getElementById('src_long').value = x.latLng.lng();
document.getElementById('pickup_location').innerHTML = x.latLng.lat()+' , '+x.latLng.lng();
var geocoder = new google.maps.Geocoder;
var infowindow = new google.maps.InfoWindow;
geocodeLatLng(geocoder, map, infowindow,x.latLng.lat(),x.latLng.lng(),'source_point');
});
//Add marker upon clicking on map
//google.maps.event.addDomListener(map, 'click', addMarker);
google.maps.event.addDomListener(map, 'click', function() { addMarker(map); });
var places1 = new google.maps.places.Autocomplete(document.getElementById('source_point'));
google.maps.event.addListener(places1, 'place_changed', function () {
var place1 = places1.getPlace();
var src_addr = place1.formatted_address;
var src_lat = place1.geometry.location.lat();
var src_long = place1.geometry.location.lng();
var mesg1 = "Address: " + src_addr;
mesg1 += "\nLatitude: " + src_lat;
mesg1 += "\nLongitude: " + src_long;
//alert(mesg1);
document.getElementById('src_lat').value = src_lat;
document.getElementById('src_long').value = src_long;
document.getElementById('pickup_location').innerHTML = src_lat+' , '+src_long;
});
//Add marker upon place change
//google.maps.event.addDomListener(places1, 'place_changed', addMarker);
google.maps.event.addDomListener(places1, 'place_changed', function() { addMarker(map); });
}
google.maps.event.addDomListener(window,'resize',initialize);
google.maps.event.addDomListener(window, 'load', initialize);
My HTML code looks like this:
<form role="form" id="frm_source" name="frm_source" method="POST" action="index_action.php">
<div class="form-group">
<label for="source_point"><h2>Pickup Address</h2></label>
<textarea type="text" id="source_point" name="source_point" class="form-control" placeholder="Enter your pick up address here"></textarea>
</div>
<div class="form-group">
<label for="pickup_location"><h3>GPS Cordinates</h3></label>
<hr>
<p id="pickup_location"></p>
</div>
<div class="form-group">
<input type="hidden" id="src_lat" name="src_lat" placeholder="latitude" >
<input type="hidden" id="src_long" name="src_long" placeholder="longitude" >
</div>
<input type="submit" name="submit" id="submit" class="btn btn-primary" value="Next to enter destination address" />
</form>
Google Map
<div id="source_map"></div>
Your field is TEXTAREA
, and from last updates, google maps autocomplete now supports only window.HTMLInputElement (INPUT tag)
:-(
这篇关于InvalidValueError:不是HTMLInputElement的实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!