Benim uygulamadan birinde google map "includesLocation()" API kullanmayı planlıyorum. doc link - Ben aynı örneği takip ediyorum https://goo.gl/4BFHCzGoogle harita hatası - a.lng bir fonksiyon değildir
. İşte benim kodum.
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Polygon arrays</title>
<style>
html, body {
height: 100%;
margin: 0;
padding: 0;
}
#map {
height: 100%;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
// This example requires the Geometry library. Include the libraries=geometry
// parameter when you first load the API. For example:
// <script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&libraries=geometry">
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
//center: {lat: 24.886, lng: -70.269},
center: {lat: 12.9629277, lng: 77.7178972},
zoom: 30,
});
/*var triangleCoords = [
{lat: 25.774, lng: -80.19},
{lat: 18.466, lng: -66.118},
{lat: 32.321, lng: -64.757}
];*/
var triangleCoords = [
{lat: 12.96301273, lng: 77.71785952},
{lat: 12.96314857, lng: 77.71784072},
{lat: 12.96316124, lng: 77.71784037},
{lat: 12.96295465, lng: 77.71788993},
{lat: 12.96293329, lng: 77.7179345},
];
var bermudaTriangle = new google.maps.Polygon({paths: triangleCoords});
google.maps.event.addListener(map, 'click', function(e) {
var curPosition = {"lat":12.9629277,"lng":77.7178972};
//var curPosition = e.latLng;
console.log("e content : "+JSON.stringify(e.latLng));
console.log("curPosition content : "+JSON.stringify(curPosition));
var resultColor =
google.maps.geometry.poly.containsLocation(curPosition, bermudaTriangle) ?
'red' :
'green';
new google.maps.Marker({
position: curPosition,
map: map,
icon: {
path: google.maps.SymbolPath.CIRCLE,
fillColor: resultColor,
fillOpacity: .2,
strokeColor: 'white',
strokeWeight: .5,
scale: 10
}
});
});
}
</script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCiAur6ANJsV776iVmMDJcHYjQkXrXyu8s&libraries=geometry&callback=initMap"
async defer></script>
</body>
</html>
ben LatLng verileri tutan bir curPosition
değişken oluşturduk görürseniz. o, ben var curPosition = {"lat":12.9629277,"lng":77.7178972};
için bu hatayı "Uncaught TypeError: a.lng is not a function"
gösteren başlamış değişti anı çalışıyor ancak bu süre var curPosition = e.latLng;
burada Benim sorundur.
Niçin olduğunu anlayamıyor musunuz? Bir ipucu...?
console.log ekran görüntüsü (en azından şu anda) containsLocation
yöntemi "noktası" olarak google.maps.LatLng gerektirir
Saygılarımızla
Burada sahip konsol günlükleri göndermek için yardımcı olabilir. Özellikle JSON.stringify (e.latLng) – user2263572
Bir ** google.maps.LatLng ** nesnesini geçirmeyi deneyin: "var curPosition = yeni google.maps.LatLng (12.9629277, 77.7178972);" –
@ user2263572: console.log ekran görüntüsü ekli – mi6crazyheart