Last active
April 5, 2016 06:05
-
-
Save kurozumi/e10e6ec3105f8c5fc035eab95ce791c3 to your computer and use it in GitHub Desktop.
【WordPress】HTML5のGeolocation APIを使ってBasic Google Maps Placemarksプラグインの地図を表示するショートコードに現在地へ移動するボタンを追加する方法
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript"> | |
var bgmpData = { | |
options: <?php echo json_encode( $this->getMapOptions( $attributes ) ); ?>, | |
markers: <?php echo json_encode( $this->getMapPlacemarks( $attributes ) ); ?> | |
}; | |
(function($){ | |
$(document).ready(function(){ | |
$("#getLocation").on("click", function(){ | |
navigator.geolocation.getCurrentPosition(is_success,is_error); | |
function is_success(position) { | |
bgmpData.options.latitude = position.coords.latitude; | |
bgmpData.options.longitude = position.coords.longitude; | |
bgmp_wrapper( $ ); | |
} | |
function is_error(error) {} | |
}); | |
}); | |
})(jQuery); | |
</script> | |
<p><button id="getLocation">現在地へ移動</button></p> | |
<div id="<?php echo self::PREFIX; ?>map-canvas"> | |
<p><?php _e( 'Loading map...', 'basic-google-maps-placemarks' ); ?></p> | |
<p><img src="<?php echo plugins_url( 'images/loading.gif', dirname( __FILE__ ) ); ?>" alt="<?php _e( 'Loading', 'basic-google-maps-placemarks' ); ?>" /></p> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment