2017-11-30 9 views
0

は、私がOMSが定義されていませんか? 「oms.addmarker(マーカー);」の開発ツールで私のコードの検査の際

Uncaught ReferenceError: oms is not defined 
at map.1.js:94 
at create_marker (map.1.js:96) 

私のアプリケーションが正常にポイントをマッピングされていない、次のエラーが発生しますしかし、それは通常の "markers.push(マーカー);"誰かが私に何が変わる必要があるかを教えてもらえれば、このエラーの原因となっているインスタンス化がダウンしている可能性があると思います。

var markers = []; // To erase markers later 
 
var user_lat = 52.358409; // Random default location 
 
var user_lng = -1.549072; 
 
/*global geocoder*/ 
 
/*global google*/ 
 
/*global map*/ 
 
/*global draggable_marker*/ 
 
/*global custom_icons*/ 
 
/*global OverlappingMarkerSpiderfier*/ 
 
/*global new_lat*/ 
 
/*global navigator*/ 
 
/*global create_crime_markers*/ 
 
/*global new_lng*/ 
 
/*global marker*/ 
 

 
function map_callback(){ 
 
    // Without var = set to global scope 
 
    geocoder = new google.maps.Geocoder(); 
 
    var new_location = new google.maps.LatLng(user_lat, user_lng); 
 
    var map_properties = {center: new_location, zoom: 15, mapTypeId: "hybrid", zoomControlOptions: {style: google.maps.ZoomControlStyle.SMALL, position: google.maps.ControlPosition.LEFT_BOTTOM}, streetViewControlOptions:{position: google.maps.ControlPosition.LEFT_BOTTOM}}; 
 
    map = new google.maps.Map(document.getElementById("google_map"), map_properties); 
 
    var iw = new google.maps.InfoWindow(); 
 
    var oms = new OverlappingMarkerSpiderfier(map, { 
 
    
 
     markersWontMove: true, // we promise not to move any markers, allowing optimizations 
 
     markersWontHide: true, // we promise not to change visibility of any markers, allowing optimizations 
 
     basicFormatEvents: true // allow the library to skip calculating advanced formatting information 
 
     }); 
 
    draggable_marker = new google.maps.Marker({ 
 
     position: new_location, 
 
     map: map, 
 
     draggable: true, 
 
     title: "Drag me", 
 
     icon: "./img/blue_marker.png" 
 
    }); 
 
    google.maps.event.addListener(draggable_marker, "dragend", function(){draggable_callback();}); 
 
    google.maps.event.addListener(map, "click", function(event){draggable_callback(event.latLng);}); 
 
    draggable_callback(); // Trigger first load 
 
    
 
     for (var i = 0, len = marker.length; i < len; i ++) { 
 
     (function() { // make a closure over the marker and marker data 
 
      var markerData = marker[i]; // e.g. { lat: 50.123, lng: 0.123, text: 'XYZ' } 
 
      var marker = new google.maps.Marker({ position: markerData }); // markerData works here as a LatLngLiteral 
 
      google.maps.event.addListener(marker, 'spider_click', function(e) { // 'spider_click', not plain 'click' 
 
      iw.setContent(marker.title); 
 
      iw.open(map, marker); 
 
      }); 
 
      oms.addMarker(marker); // adds the marker to the spiderfier _and_ the map 
 
      console.log(marker); 
 
     })(); 
 
     } 
 
} 
 

 
function search(){ 
 
    var address = document.getElementById("search_box").value; 
 
    if (address != ""){ 
 
    geocoder.geocode({ 
 
     "address": address, 
 
     componentRestrictions: {country: "UK"} 
 
     }, 
 
     function(results, status){ 
 
     if (status == "OK") { 
 
      var loc = results[0].geometry.location 
 
      draggable_callback(loc); 
 
      map.panTo(loc); 
 
     } else { 
 
      alert("Cannot perform search, reason: " + status); 
 
     } 
 
    }); 
 
    } 
 
} 
 

 
function clear_markers(){ 
 
    for (var i = 0; i < markers.length; i++){ 
 
    markers[i].setMap(null); 
 
    } 
 
    markers = []; 
 
} 
 

 
function create_marker(lat, lng, title){ 
 
    var current_lat_lng = lat.toString() + lng.toString(); 
 
     (function() { // make a closure over the marker and marker data 
 
    // Default icon 
 
    var custom_icon = "https://maps.gstatic.com/mapfiles/api-3/images/spotlight-poi.png"; 
 
    if (title in custom_icons) {custom_icon = custom_icons[title];} 
 
    var marker = new google.maps.Marker({ 
 
     position: new google.maps.LatLng(lat, lng), 
 
     map: map, 
 
     icon: custom_icon, 
 
     title: title}); 
 
     google.maps.event.addListener(marker, 'spider_click', function(e) { // 'spider_click', not plain 'click' 
 
      }); 
 
      oms.addMarker(marker); 
 

 
     })(); 
 
     } 
 
    
 

 
function draggable_callback(loc){ 
 
    if (loc != undefined) {draggable_marker.setPosition(loc);} 
 

 
    new_lat = draggable_marker.getPosition().lat(); 
 
    new_lng = draggable_marker.getPosition().lng(); 
 

 
    console.log(new_lat, new_lng); 
 
    clear_markers(); 
 
    create_crime_markers(new_lat, new_lng); 
 
} 
 

 
function get_my_loc(){ 
 
    if (navigator.geolocation){ 
 
    navigator.geolocation.getCurrentPosition(success_callback, error_callback); 
 
    } 
 
} 
 

 
function success_callback(position){ 
 
    var new_location = new google.maps.LatLng(position.coords.latitude, position.coords.longitude); 
 
    draggable_callback(new_location); 
 
    map.panTo(new_location); 
 
    
 
} 
 

 
function error_callback(error){ 
 
    switch(error.code){ 
 
    case error.PERMISSION_DENIED: 
 
     alert("Denied request for Geolocation"); 
 
     break; 
 
    case error.POSITION_UNAVAILABLE: 
 
     alert("Your location information is unavailable"); 
 
     break; 
 
    case error.TIMEOUT: 
 
     alert("The request to get your location timed out"); 
 
     break; 
 
    case error.UNKNOWN_ERROR: 
 
     alert("An unknown error in finding your location occurred"); 
 
     break; 
 
    } 
 
}
<div id="google_map"></div>

var markers = []; // To erase markers later 
var user_lat = 52.358409; // Random default location 
var user_lng = -1.549072; 
/*global geocoder*/ 
/*global google*/ 
/*global map*/ 
/*global draggable_marker*/ 
/*global custom_icons*/ 
/*global OverlappingMarkerSpiderfier*/ 
/*global new_lat*/ 
/*global navigator*/ 
/*global create_crime_markers*/ 
/*global new_lng*/ 
/*global marker*/ 

function map_callback(){ 
    // Without var = set to global scope 
    geocoder = new google.maps.Geocoder(); 
    var new_location = new google.maps.LatLng(user_lat, user_lng); 
    var map_properties = {center: new_location, zoom: 15, mapTypeId: "hybrid", zoomControlOptions: {style: google.maps.ZoomControlStyle.SMALL, position: google.maps.ControlPosition.LEFT_BOTTOM}, streetViewControlOptions:{position: google.maps.ControlPosition.LEFT_BOTTOM}}; 
    map = new google.maps.Map(document.getElementById("google_map"), map_properties); 
    var iw = new google.maps.InfoWindow(); 
    var oms = new OverlappingMarkerSpiderfier(map, { 

     markersWontMove: true, // we promise not to move any markers, allowing optimizations 
     markersWontHide: true, // we promise not to change visibility of any markers, allowing optimizations 
     basicFormatEvents: true // allow the library to skip calculating advanced formatting information 
     }); 
    draggable_marker = new google.maps.Marker({ 
     position: new_location, 
     map: map, 
     draggable: true, 
     title: "Drag me", 
     icon: "./img/blue_marker.png" 
    }); 
    google.maps.event.addListener(draggable_marker, "dragend", function(){draggable_callback();}); 
    google.maps.event.addListener(map, "click", function(event){draggable_callback(event.latLng);}); 
    draggable_callback(); // Trigger first load 

     for (var i = 0, len = marker.length; i < len; i ++) { 
     (function() { // make a closure over the marker and marker data 
      var markerData = marker[i]; // e.g. { lat: 50.123, lng: 0.123, text: 'XYZ' } 
      var marker = new google.maps.Marker({ position: markerData }); // markerData works here as a LatLngLiteral 
      google.maps.event.addListener(marker, 'spider_click', function(e) { // 'spider_click', not plain 'click' 
      iw.setContent(marker.title); 
      iw.open(map, marker); 
      }); 
      oms.addMarker(marker); // adds the marker to the spiderfier _and_ the map 
      console.log(marker); 
     })(); 
     } 
} 

function search(){ 
    var address = document.getElementById("search_box").value; 
    if (address != ""){ 
    geocoder.geocode({ 
     "address": address, 
     componentRestrictions: {country: "UK"} 
     }, 
     function(results, status){ 
     if (status == "OK") { 
      var loc = results[0].geometry.location 
      draggable_callback(loc); 
      map.panTo(loc); 
     } else { 
      alert("Cannot perform search, reason: " + status); 
     } 
    }); 
    } 
} 

function clear_markers(){ 
    for (var i = 0; i < markers.length; i++){ 
    markers[i].setMap(null); 
    } 
    markers = []; 
} 

function create_marker(lat, lng, title){ 
    var current_lat_lng = lat.toString() + lng.toString(); 
     (function() { // make a closure over the marker and marker data 
    // Default icon 
    var custom_icon = "https://maps.gstatic.com/mapfiles/api-3/images/spotlight-poi.png"; 
    if (title in custom_icons) {custom_icon = custom_icons[title];} 
    var marker = new google.maps.Marker({ 
     position: new google.maps.LatLng(lat, lng), 
     map: map, 
     icon: custom_icon, 
     title: title}); 
     google.maps.event.addListener(marker, 'spider_click', function(e) { // 'spider_click', not plain 'click' 
      }); 
      oms.addMarker(marker); 

     })(); 
     } 


function draggable_callback(loc){ 
    if (loc != undefined) {draggable_marker.setPosition(loc);} 

    new_lat = draggable_marker.getPosition().lat(); 
    new_lng = draggable_marker.getPosition().lng(); 

    console.log(new_lat, new_lng); 
    clear_markers(); 
    create_crime_markers(new_lat, new_lng); 
} 

function get_my_loc(){ 
    if (navigator.geolocation){ 
    navigator.geolocation.getCurrentPosition(success_callback, error_callback); 
    } 
} 

function success_callback(position){ 
    var new_location = new google.maps.LatLng(position.coords.latitude, position.coords.longitude); 
    draggable_callback(new_location); 
    map.panTo(new_location); 

} 

function error_callback(error){ 
    switch(error.code){ 
    case error.PERMISSION_DENIED: 
     alert("Denied request for Geolocation"); 
     break; 
    case error.POSITION_UNAVAILABLE: 
     alert("Your location information is unavailable"); 
     break; 
    case error.TIMEOUT: 
     alert("The request to get your location timed out"); 
     break; 
    case error.UNKNOWN_ERROR: 
     alert("An unknown error in finding your location occurred"); 
     break; 
    } 
} 

答えて

0

たぶん私は何かが足りないんだけど、私はあなたのhtmlヘッダにOMSが表示されていない。

<script src="https://cdnjs.cloudflare.com/ajax/libs/OverlappingMarkerSpiderfier/1.0.3/oms.min.js"> 
関連する問題