gmaps4rails detect_location is not showing marker - ruby-on-rails-3

I am working with gem "gmaps4rails" in rails 3.2.12, I had set the detect_location = "true" in map_options, but it is not showing any marker with user current location.
Here is code:
<%= gmaps("map_options" => {"auto_adjust" => true, "detect_location" => true, "center_on_user" => true, "auto_zoom" => false, "radius" => 2500},
"markers" => {"data" => #json, "options" => {"list_container" => "markers_list","randomize" => true,"max_random_distance" => 10000, "draggable" => true, "dblclick" => "latLng"} }
How to show with marker for the user current location.
Please help me.
Thanks in Advance

With the gem "gmaps4rails",
if we give the option "detect_location" => true, when the map loads on page, it shows pop-up to user as 'allow application to use your location' and gives yes and no as options.
If user selects 'yes', then map get centered to user's location.
Now here you want to display marker for user's location, then you have to add marker by your own.
This can be done as follows:
Controller:
geo = request.location
#latitude = geo.latitude
#longitude = geo.longitude
With your page load, you can add marker for user, with this callback.
This would add marker for current user location when map loads on page.
- content_for :scripts do
%script{:type => "text/javascript"}
Gmaps.map.callback = function(){
google.maps.event.addListenerOnce(Gmaps.map.serviceObject, 'idle', function(){
/ add user pin
var home_pin = [{picture: "current_user.png", width: 32, lat: "#{#latitude}", lng: "#{#longitude}"}];
Gmaps.map.addMarkers(home_pin)
}
)};
Hope this would help you.
Let me know if you still face any issues.
Thanks.

Related

Remove OK button from kartik-v custom dialog

I tried to create a custom dialog using yii2-dialog, one of the kartik-v widgets. I want to create this dialog with a single button: Statistics so, using the documentation provided in the demo, I wrote the code below.
The problem is that the dialog I get has two buttons instead of one and I CAN NOT get rid of the OK button.
My questions are: is there any way to create a custom dialog using yii2-dialog with a single button? and if possible, how can I achieve this?
use kartik\dialog\Dialog;
use yii\web\JsExpression;
echo Dialog::widget([
'libName' => 'krajeeDialogCust',
'overrideYiiConfirm' => false,
'options' => [
'size' => Dialog::SIZE_LARGE,
'type' => Dialog::TYPE_SUCCESS,
'title' => 'My Dialog',
'message' => 'This is an entirely customized bootstrap dialog from scratch.',
'buttons' => [
[
'id' => 'cust-btn-1',
'label' => 'Statistics',
'action' => new JsExpression("function(dialog) {
dialog.setTitle('Title 1');
dialog.setMessage('This is a custom message for button number 1');
}")
],
]
]
]);
// button for testing the custom krajee dialog box
echo '<button type="button" id="btn-custom" class="btn btn-success">Custom Dialog</button>';
// javascript for triggering the dialogs
$js = <<< JS
$("#btn-custom").on("click", function() {
krajeeDialogCust.dialog(
"Welcome to a customized Krajee Dialog! Click the close icon on the top right to exit.",
function(result) {
// do something
}
);
});
JS;
// register your javascript
$this->registerJs($js);
And this is what I'm getting:
You need to use dialogDefaults option, according to the docs the configuration options to be setup as defaults for the bootstrap dialog (applicable when useNative is false). and the default value for useNative is false until you explicitly set to true.
Update your Dialog definition to below and override the buttons property in the dialogDefault option as the plugin sets the ok and cancel buttons by default.
echo Dialog::widget ( [
'libName' => 'krajeeDialogCust' ,
'overrideYiiConfirm' => false ,
'dialogDefaults' => [
Dialog::DIALOG_OTHER => [
'buttons' => ''
]
] ,

kartik yii2 mpdf - set header height

I am using kartik mpdf in YII2. And I need to show the full header in every page. It may have a height of 450px.
Currently it's shown as above. How can I fix it?
marginTop: float, sets the page top margin for the new document (in millimetres).
You can use 'marginTop' => 119
The margins can be set using the syntax below, for the top margin adjust the marginTop as required
new Pdf([
'mode' => '', // leaner size using standard fonts
'format' => Pdf::FORMAT_A4,
'orientation' => Pdf::ORIENT_LANDSCAPE,
'marginTop' => 0,
'marginBottom' => 0,
'marginLeft' => 0,
'marginRight' => 0,
'destination' => Pdf::DEST_BROWSER,
'content' => $this->renderPartial('certificate_pdf', ['']),
'options' => [
// any mpdf options you wish to set
],
'methods' => [
'SetTitle' => '',
'SetSubject' => '',
'SetHeader' => [''],
'SetFooter' => [''],
'SetAuthor' => 'Ajira Tracking',
'SetCreator' => 'Ajira Tracking',
'SetKeywords' => 'Ajira Tracking',
]
]);

Google-Maps-for-Rails Direction Wiki Explaination Needed

Hi I am currently working on a trash bin/recycling bin location application using google maps for rails.
I have a recyclingbin.rb model with the address as its attributes, that itself is enough to put markers on a map that can get displayed using the gem. I believe the gem converts the model and its attributes into json data.
I am trying to implement a feature where I can input my location and get direction to the nearest marker.
I have looked at the wiki , https://github.com/apneadiving/Google-Maps-for-Rails/wiki/Direction
Am I suppose to put this in the view ?
{ "data" => { "from" => "Paris, france", "to" => "Toulon, france" } }
})
%>
with the from to be embedded with my location for now? I understand I can pass options to this reference from google.
The wiki is quite short, can someone give me a quick explanation ?
The wiki does need some more work. I have a simple app working that shows the directions on the map from a location to another (pre-defined) location
<%= gmaps("map_options" => {"zoom" => 14}, "markers" => { "data" => #json },
"direction" => { "data" => {"from" => #location.address, "to" => "New York City"},"travelMode" => "DRIVING"}) %>
I just put this in my view. It shouldn't matter where, just as long as its there. Hope this helps

Setting header size in PDFKit with Ruby on Rails?

I need a repeating image to be shown on every page of the pdf. The only solution to this I've found so far is putting it into the header using
%meta{:name => 'pdfkit-header_html', :content => pdf_header_url}
Works fine but the image is bigger than the header size. Is there any way I can increase the height of the header or put a repeating image somehow outside the header?
Thanks!
You'll need to tweak the margin-top and header-spacing values. For example:
%meta{:name => 'pdfkit-header_html', :content => pdf_header_url}
%meta{:name => 'pdfkit-margin_top', :content => '3cm' }
%meta{:name => 'pdfkit-header_spacing', :content => '10' }
From the wkhtmltopdf docs:
--header-spacing * <real> Spacing between header and content in mm
(default 0)
-T, --margin-top <unitreal> Set the page top margin (default 10mm)
You can put any of the wkpdftohtml options in the meta tags and PDFKit will pass them through.
I ended up adding this code
PDFKit.configure do |config|
config.default_options = {
:page_size => 'Letter',
:margin_top => '3.6in',
:margin_right => '0.3in',
:margin_bottom => '1.3in',
:margin_left => '0.3in'
}
end
to /config/initializers/pdfkit.rb. Worked like charm after I restarted the server.

Geodesic routes in gmaps4rails

I can currently draw polylines using gmaps4rails in Rails but I'd like to draw them as geodesic paths. According to the Google Map documentation this should be as simple as adding "geodesic: true" to the options (link). Below is my current implementation that doesn't work but simply draws a straight line on the map. Is there a correct way of setting this option in gmaps4rails or is this not currently supported?
In my controller:
#json_route =
[
[
{'lng' => 80.190262, 'lat' => 55.774252 },
{'lng' => -66.118292, 'lat' => 38.466465 }
]
]
#gmaps_options =
{
:polylines => { "data" => #json_route.to_json, "options" => { "geodesic" => true }}
}
In my html page:
<%= gmaps(#gmaps_options) %>
Thank you!