Skip to content

Instantly share code, notes, and snippets.

@kurozumi
Last active April 5, 2016 06:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kurozumi/e10e6ec3105f8c5fc035eab95ce791c3 to your computer and use it in GitHub Desktop.
Save kurozumi/e10e6ec3105f8c5fc035eab95ce791c3 to your computer and use it in GitHub Desktop.
【WordPress】HTML5のGeolocation APIを使ってBasic Google Maps Placemarksプラグインの地図を表示するショートコードに現在地へ移動するボタンを追加する方法
<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