var handler = Gmaps.build('Google');
handler.buildMap({ internal: {id: 'geolocation'} }, function(){
if(navigator.geolocation)
navigator.geolocation.getCurrentPosition(displayOnMap);
});
function displayOnMap(position){
var marker = handler.addMarker({
lat: position.coords.latitude,
lng: position.coords.longitude
});
handler.map.centerOn(marker);
};
I can get my current location on the screen by this way. How can I get the specific location that all clients will see the same adress.
For displaying one specific location using Google map API, I think you can work directly with the HTML/CSS portion of your Rails app, insead of having to add a gem.
See this tutorial - https://developers.google.com/maps/tutorials/fundamentals/adding-a-google-map
and just follow the Rails MVC structure to put your code in the right files. This should also be relatively easier since you have already worked with Geocoder and Gmaps4rails.
Related
I want to send current user location coordinates (LatLong) automatically to mysql database using webservices with update every 5 seconds,, and in another app get the coordinates from mysql to plot markers on map. can anyone give me sample tutorial or project or example or any help, I am new in xamarin
You should use a plugin for this purpose. This plugin is called Geolocator.
You can see their documentation here.
Your source code here.
And you can get the location every 5 seconds as follows:
using Plugin.Geolocator;
var position = await locator.GetPositionAsync (timeoutMilliseconds: 5000);
Console.WriteLine ("Position Status: {0}", position.Timestamp);
Console.WriteLine ("Position Latitude: {0}", position.Latitude);
Console.WriteLine ("Position Longitude: {0}", position.Longitude);
And if you are continuously monitoring a user’s location, such as for a maps application, you can also tap into the PositionChanged event to receive updated coordinates:
locator.PositionChanged += (sender, e) => {
var position = e.Position;
latitudeLabel.Text = position.Latitude;
longitudeLabel.Text = position.Longitude;
};
For more information see this tutorial.
For render maps options you can see this documentation
This link is all you need :
https://developer.xamarin.com/recipes/android/os_device_resources/gps/get_current_device_location/
Also after API-24 runtime permissions are required which you will find here
https://blog.xamarin.com/requesting-runtime-permissions-in-android-marshmallow/
When using Google API what will be the data that is needed for an application that shows locations of different places,is latitude and longitude will be necessary , the locations that needed to shown is already in Google maps. Or just the address or the name of the place will be enough.
Can anybody help me ?
When placing markers on a map at a minimum you need the lat and long vertices.
You can use a various Google APIS for getting data like a Google Places library to search by a place name or address: https://developers.google.com/maps/documentation/javascript/examples/places-searchbox
You can also use a reverse geocode service to search by a lat long: https://developers.google.com/maps/documentation/javascript/examples/geocoding-reverse
Or if you have your own data you can create the markers like shown in this example:
var myLatlng = new google.maps.LatLng(36.166461, -86.771289);
app.marker = new google.maps.Marker({
position: (myLatlng),
data:this,
map: app.map,
title: 'Hello marker!!'
});
https://jsfiddle.net/loanburger/48asvsed/
I have seen previous posts regarding the conversion from a Google Place ID to an address; however I am interested in the opposite.
I have the GMS Address of the desired location but I want to acquire the Google Place ID in order to present more details to the user. From what I have seen on Google's iOS API website, you can attain a Google Place ID from an Autocomplete feature (for user searching), a selected location feature, or a current location feature.
My application intends to display multiple locations in which I already have the addresses for. The user can select individual locations for more details in addition to receiving details upon arrival. Therefore the features listed above are not ideal.
I have also tried using Google's Web API with features such as "Text Search Requests" & "Nearby Search Requests" however I am receiving "Zero Results".
Are there other methods that I haven't thought of and/or seen?
How about the Place ID finder in the Google Maps JavaScript API.
A place ID is a textual identifier that uniquely identifies a place. It is also available for most locations, including businesses, landmarks, parks, and intersections. These IDs are stable, meaning that once you've identified the place ID for a place, you can reuse that value when you next look up that place.
You can use the same place ID across the Google Places API and a number of Google Maps APIs. For example, you can use the same place ID to reference a place in the Places API, the Google Maps JavaScript API, the Google Maps Geocoding API, the Google Maps Embed API and the Google Maps Roads API.
Here is the sample code use for this.
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
center: {lat: -33.8688, lng: 151.2195},
zoom: 13
});
var input = document.getElementById('pac-input');
var autocomplete = new google.maps.places.Autocomplete(input);
autocomplete.bindTo('bounds', map);
map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);
var infowindow = new google.maps.InfoWindow();
var marker = new google.maps.Marker({
map: map
});
marker.addListener('click', function() {
infowindow.open(map, marker);
});
autocomplete.addListener('place_changed', function() {
infowindow.close();
var place = autocomplete.getPlace();
if (!place.geometry) {
return;
}
if (place.geometry.viewport) {
map.fitBounds(place.geometry.viewport);
} else {
map.setCenter(place.geometry.location);
map.setZoom(17);
}
// Set the position of the marker using the place ID and location.
marker.setPlace({
placeId: place.place_id,
location: place.geometry.location
});
marker.setVisible(true);
infowindow.setContent('<div><strong>' + place.name + '</strong><br>' +
'Place ID: ' + place.place_id + '<br>' +
place.formatted_address);
infowindow.open(map, marker);
});
}
Just take note that this example requires the Places library. Include
the libraries=places parameter when you first load the API. For
example:
script src="https://maps.googleapis.com/maps/api/jskey=YOUR_API_KEY&libraries=places"
I am using gmaps4rails and trying to set a temporary marker (the client side) on the screen without saving it to the database, and presenting a infowindow with a rails form (server side).
I know that it is a bit tricky because I need to get the server side to give me the form at the moment of creation.
I tried the following code, but my logic in the infowindow part is wrong.
function show_location(lat, lng){
var tempmarker = {lat: lat, lng: lng, "infowindow": tempmarker.html('#{escape_javascript(render :partial => "form")}')}
handler.addMarker(tempmarker);
};
I also looked at this option on the gmaps4rails guide , but I don't think it will help me
Gmaps.map.jsTemplate = function(marker_container){
//whatever you need
return your_html;
}
any suggestions?
I am new to html 5 geolocation, Is there any site or examples where it shows how, i can use html geolocation api to track the location of other devices. Also, for example how can i use use HTML5 geolocation to find the nearest car dealer say 5 or 10 miles from me?
Any examples sample would be really helpfull.
thanks
I can't speak to tracking devices, but i've been writing something that might help with the second part of your question.
//check browser support
if(navigator.geolocation) {
//do the geolocation stuff
navigator.geolocation.getCurrentPosition(function(position) {
//make a string out of the coordinates
var initloc_str = position.coords.latitude + ', ' + position.coords.longitude;
//pass it to a function that searches for donut shops near the coordinates
donutSearch(initloc_str);
});
} else { // if no browser support, error message or whatever
My donut shop search function is based on the local search in Google's Ajax search API, I found this article on webmonkey helpful for that bit. That API was recently deprecated but I haven't figured out how to do local search with their new Custom Search API yet.
You can register a function for tracking positions of a user:
var watchId = navigator.geolocation.watchPosition(function(position) {
console.log(position.coords.latitude);
console.log(position.coords.longitude);
});
And you can unregister:
navigator.geolocation.clearWatch(watchId);
This site will give you a awesome overview of the HTML5 geolocation Capability.