Yandex map creates two cards, how to fix?

I'm not strong in JS for this please suggest how to fix this.

JS
<script type="text/javascript">

 function address_value(city_name)
{
alert(city_name.value);
$.ajax({
 url: 'http://geocode-maps.yandex.ru/1.x/?geocode='+ city_name.value +'&format=json&results=1', // specify the URL and
 dataType : "json", // the input data type
 success: function (data) { // hang your handler in the success function
 var coords = data.response.GeoObjectCollection.featureMember[0].GeoObject.Point.pos;
 // the format comes in Latitude-Longitude, we divide the coordinates into variables.
 var coordMap = coords.split(' ');
 var longitude = coordMap[0];
 var latitude = coordMap[1];

ymaps.ready(init);
 var myMap,
myPlacemark;

 function init(){
 myMap = new ymaps.Map("map", {
 center: [latitude, longitude],
 zoom: 16
});

 myPlacemark = new ymaps.Placemark([latitude, longitude], {
 hintContent: 'Moscow!',
 balloonContent: 'Capital of Russia'
});

myMap.geoObjects.add(myPlacemark);
}
}
});
}

</script>


HTML
<input type="text" id="find" name="plz" onchange="address_value(this);">

<div id="map" style="width: 100%; height: 400px"></div>


On the first request everything is OK. second, it generates the same map below with the new town. How do I clear the contents of the Map ? I tried using InnerHTML, but to no avail. I new request to display in the same map?
July 4th 19 at 23:50
3 answers
July 4th 19 at 23:52
Solution
before var myMap

if(myMap){
myMap.destroy()
}
Why on every request map delete/create new? - Nash_Marv commented on July 4th 19 at 23:55
: because he says that generates a second and asked how to remove the first) - Abdul.Stiedemann commented on July 4th 19 at 23:58
I did but not working. Why not destroys the object. Although in the documentation of the destruction of the card is the same way. - heber_Prohas commented on July 5th 19 at 00:01
: Globally you came. No, well, as the option will go, of course. :) - Nash_Marv commented on July 5th 19 at 00:04
July 4th 19 at 23:54
Solution
Resolved the issue so source code. search by address.

<input type="text" id="find" name="plz" onchange="address_value(this);">

<script type="text/javascript">
 var myMap, myPlacemark;

 function address_value(city_name)
{
alert(city_name.value);

$.ajax({
 url: 'http://geocode-maps.yandex.ru/1.x/?geocode='+ city_name.value +'&format=json&results=1', 
 dataType : "json", 
 success: function (data) { 
 var coords = data.response.GeoObjectCollection.featureMember[0].GeoObject.Point.pos;
 var coordMap = coords.split(' ');
 var longitude = coordMap[0];
 var latitude = coordMap[1];

 function init () {
if(myMap){
myMap.destroy();
 myMap = null;
}
 myMap = new ymaps.Map("map", {
 center: [latitude, longitude],
 zoom: 16
});

 myPlacemark1 = new ymaps.Placemark([latitude, longitude], {
 hintContent: 'Moscow!',
 balloonContent: 'Capital of Russia'
});

myMap.geoObjects.add(myPlacemark1);
}
ymaps.ready(init);
}
});
}
</script>

<div id="map" style="width: 100%; height: 400px"></div>
July 4th 19 at 23:56
removeChild, and then draw a new card?

Find more questions by tags JavaScript