如何在地图中不断显示指示我位置的标记?这是一个很好的功能。
答案 0 :(得分:0)
假设您使用的是最高主题:
a. Add the string "My current position"
themes\supreme-directory\functions.php Line 89 in function sd_enqueue_styles()
Replace
wp_enqueue_script('supreme', get_stylesheet_directory_uri() . '/js/supreme.js', array(), SD_VERSION, true);
with
wp_enqueue_script('supreme', get_stylesheet_directory_uri() . '/js/supreme.js', array(), SD_VERSION, true);
$translation_array = array('currPosText' => __( 'My current position', 'gdlocation' ));
wp_localize_script( 'supreme', 'phpvarsMyLocation', $translation_array );
a. Add to supreme.js not inside onready function supreme.js at end
//============== Show current position functions =======================
function gdMyGeoCurrentLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(gdMyGeoMyCurrentLocationSuccess, gdMyGeoPositionError);
} else {
gdMyGeoPositionError(-1);
}
}
function gdMyGeoMyCurrentLocationSuccess(position) {
var coords = position.coords || position.coordinate || position;
if (coords && coords.latitude && coords.longitude) {
var myLat = coords.latitude,
myLng = coords.longitude;
var geoAddress = myLat + ', ' + myLng;
if (window.gdMaps == 'google' || window.gdMaps == 'osm') {
//gdMyGeoGetDirections(geoAddress);
gdMyGeoShowLocation(myLat, myLng);
}
}
}
function gdMyGeoShowLocation(lt, ln) {
if (!lt) {
return false;
}
if (window.gdMaps == 'google') {
var currPosMarker = jQuery.goMap.createMarker({
id: "-10",
title: phpvarsMyLocation.currPosText,
position: new google.maps.LatLng(lt, ln),
visible: true,
clickable: true
});
} else if (window.gdMaps == 'osm') {
}
}
//===============================
c. In geodirectory\geodirectory-functions\map-functions\map_template_tags.php line 172
change
wp_enqueue_script('geodir-map-widget', geodir_plugin_url() . '/geodirectory-functions/map-functions/js/map.min.js',array(),false,true);
to
wp_enqueue_script('geodir-map-widget', geodir_plugin_url() . '/geodirectory-functions/map-functions/js/map.js',array(),false,true);
d. Add in map.js at line 489 (function list_markers)
// Show user current location
gdMyGeoCurrentLocation();