2016-09-05 10 views
-1

アプリケーションが正常に読み込まれたにもかかわらず、すべてがうまくいくように見えますが、このエラーはChrome Devツールで発生します。私はそれを引き起こしているものを見つけることができないようです。Google Maps API Uncaught TypeError:未定義のプロパティ 'lat'を読み取ることができません

var mapDiv = document.getElementById('map'); 
var map; 
var pos; 
var infowindow; 
var search_place; 

$.get("http://ip-api.com/json", function(data) { 
    pos = new google.maps.LatLng(data.lat, data.lon); 
    initMap(); 
    }); 

function initMap() { 
    map = new google.maps.Map(mapDiv, { 
    zoom: 15, 
    center: pos, 
    mapTypeControl: false 
    }); 

    // Display user's current location on the map 
    var curr_marker = new google.maps.Marker({ 
    position: pos, 
    map: map, 
    draggable: false, 
    animation: google.maps.Animation.DROP 
    }); 

    // Display a label that indicates user's current location 
    var contentString = '<div id="content">'+ 
     '<h3>' + 'This is you!' + '</h3>' + 
     '</div>'; 
    var curr_infowindow = new google.maps.InfoWindow(); 
    curr_infowindow.setContent(contentString); 

    infowindow = new google.maps.InfoWindow(); 

    var service = new google.maps.places.PlacesService(map); 
    service.nearbySearch({ 
    location: {lat: pos.lat(), lng: pos.lng()}, 
    radius: 1000, 
    type: ['restaurant'] 
    }, callback); 
    ... 
    ... 
    ... 

答えて

0

私はAPIを呼び出すときにコールバック要素は必要ありません。前

<script async defer 
    src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBoVzrmlxfvUBwId_KoqAF5PBnaHNDOEHU&libraries=places&callback=initMap"> 
</script> 

後:

<script async defer 
    src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBoVzrmlxfvUBwId_KoqAF5PBnaHNDOEHU&libraries=places"> 
</script> 
関連する問題