Intel XDK Geocoding - intel

I have created an application using intel XDK that determines the current location on a map. However I can not find any documentation or tutorials on how to convert the latitude and longitude to an address. Does anyone have any useful links or guidancce?
Thanks

Intel XDK does not have APIs for converting lat/lng to address, there are other reverse geocoding services, you can use google maps reverse geocoding to convert latitude/longitude to address, more information here, example below:
include google maps api script:
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>
here is reverse geocoding method:
function reverseGeocode(lat, lng){
var latlng = new google.maps.LatLng(lat, lng);
var geocoder = new google.maps.Geocoder();
geocoder.geocode({'latLng': latlng}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[1]) {
alert(results[1].formatted_address);
} else {
alert('No results found');
}
} else {
alert('Geocoder failed due to: ' + status);
}
});
}
you can get address by running: reverseGeocode(45, -122)

Related

How to get Exact User location by Using maps API?

May be similar question asked before. But I am in the middle of finding the location. When I try the following code it shows my internet providers location. and which doesnot show my current location.
function ipLookUp () {
$.ajax('http://ip-api.com/json')
.then(
function success(response) {
console.log('User\'s Location Data is ', response);
console.log('User\'s Country', response.country);
getAdress(response.lat, response.lon)
},
function fail(data, status) {
console.log('Request failed. Returned status of',
status);
}
);
}
function getAddress (latitude, longitude) {
$.ajax('https://maps.googleapis.com/maps/api/geocode/json?latlng=' + latitude + ',' + longitude + '&key=***************************************')
.then(
function success (response) {
console.log('User\'s Address Data is ', response)
},
function fail (status) {
console.log('Request failed. Returned status of',
status)
}
)
}
if ("geolocation" in navigator) {
// check if geolocation is supported/enabled on current browser
navigator.geolocation.getCurrentPosition(
function success(position) { // for when getting location is a success
console.log('latitude', position.coords.latitude, 'longitude', position.coords.longitude);
getAddress(position.coords.latitude, position.coords.longitude);
},
function error(error_message) { // for when getting location results in an error
console.error('An error has occured while retrieving location', error_message);
ipLookUp();
}
);
} else {
// geolocation is not supported
// get your location some other way
console.log('geolocation is not enabled on this browser')
ipLookUp()
}
It shows my ISP city name. But I want my current location name like this sample image.
This is sample image. and it shows my current city and street name in google search results page. But when I use the above code.it shows like this.
AS55836 Reliance Jio Infocomm Limited"
city: "Coimbatore"
country: "India"
isp: "RJIL Tamilnadu LTE SUBSCRIBER PUBLIC"
org: "Reliance Jio infocomm ltd"
Looking some experts advice to trace the location exactly.

google map javascript direction service returns zero result with TRANSIT mode

The following code returns status "OK":
$(document).ready(function(){
var directionsService = new google.maps.DirectionsService;
directionsService.route({
origin: {lat:35.059280, lng:135.753},
destination: {lat:34.981117, lng:135.748},
travelMode: google.maps.TravelMode.DRIVING,
}, function(response, status) {
console.log(status);
});
});
The following code returns status "ZERO RESULTS":
$(document).ready(function(){
var directionsService = new google.maps.DirectionsService;
directionsService.route({
origin: {lat:35.059280, lng:135.753},
destination: {lat:34.981117, lng:135.748},
travelMode: google.maps.TravelMode.TRANSIT,
}, function(response, status) {
console.log(status);
});
});
The only difference is the travelMode.
But when I manually search google map, I did get couple of routing directions in TRANSIT mode.
https://www.google.com.tw/maps/dir/35.05928,135.753/34.98117,135.748/#35.0193556,135.7110872,13z/data=!3m1!4b1!4m2!4m1!3e3
Is there anything wrong with my code?
Thanks!
Everything is OK with your code. You just need to check if transit mode data is available in Maps APIs for given city.
I understand you search route in Kyōto. Please check the coverage for Transit directions on https://developers.google.com/maps/coverage
It looks like Kyōto is not in the list and transit data isn't available via Maps APIs.

Meteor geo location from browser package

I've tried searching atmosphere and the web for any package to get users Geo location (latitude, longitude) while accessing the app using their desktop browsers but couldn't find any. Existing applications serve mobile only ex. MDG Geo Location Can someone please tell me how to get the user geo location (latitude, longitude) from desktop through Meteor? Thanks
I know this is an old post, however, thought of putting this through.
You can try using the gunjansoni:html5-api package. It has geo location and lot of other HTML5 Apis to play with.
After you install the package on you client
var html5api = new Html5Api();
and then request for geo location permissions:
var geoLocation = html5api.geoLocation();
Once you have the permissions, get the location.
if (geoLocation) {
geoLocation.getLocation(function(err, res){
if (err) console.log(err);
else console.log(res);
});
}
The result will be something like this:
{
accuracy: 30 // in meters
altitude: null
altitudeAccuracy: null
heading: null
latitude: <latitude>
longitude: <longitude>
speed: null
timestamp: 1457901207220
}
Or you can watch a user's location
if (geoLocation) {
geoLocation.watch(function (err, res) {
if (err) console.log(err);
else {
// the result will be in res.result
console.log(res.result);
Meteor.setInterval(function () {
// to stop watching a location, you need a watchId which is available in res.watchId when the watch started
geoLocation.stopWatching(res.watchId);
}, 30 * 1000);
}
});
}

Halt insert till function returns result

In my visits collection I have a geocodeVisit function which uses the Google geocoding service to gecode an address. The problem is that the meteor script is typically run before the google maps API is loaded, resulting in an Exception while invoking method 'visitInsert' ReferenceError: google is not defined error. So I need to wait with the inser till the geocoding has finished. How can I do this? This is the visits collection:
Meteor.methods({
visitInsert: function(visitAttributes) {
check(Meteor.userId(), String);
check(visitAttributes, {
nr: String,
visit_date: String
});
var properties = {
userId: Meteor.userId(),
position: geocodeVisit(visitAttributes.address)
};
var visit = _.extend(visitAttributes, properties);
var visitId = Visits.insert(visit);
return {
_id: visitId
};
}
});
geocodeVisit = function (address) {
this.unblock;
var geocoder = new google.maps.Geocoder();
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
return results[0].geometry.location;
}
});
}
Instead of including the maps api using a script tag in the HTML code, you should download the file to your "/lib" directory. Everything in that directory is loaded before any Meteor code is run.
Also, you are going to run into an async problem with you code. You are trying to return the value from the success callback in the geocodeVisit function. The two approaches that I can see working are:
Figure out how to make synchronous requests using the maps api. Maybe this: Synchronous request in Node.js
Go ahead and insert the visit without the location info. Then make the geocode request to the maps api and update the entry once the response comes back. Personally, this is the approach I would take.

google places api get location's reference value

I have this string of code from one of their examples that I'm trying to reverse engineer.
<script type="text/javascript">
function initialize() {
var map = new google.maps.Map(document.getElementById('map_canvas'), {
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: new google.maps.LatLng(36.018486,-86.787607),
zoom: 15
});
var frontline = new google.maps.LatLng(36.018486,-86.787607);
var request = {
reference: 'CnRkAAAAGnBVNFDeQoOQHzgdOpOqJNV7K9-c5IQrWFUYD9TNhUmz5-aHhfqyKH0zmAcUlkqVCrpaKcV8ZjGQKzB6GXxtzUYcP-muHafGsmW-1CwjTPBCmK43AZpAwW0FRtQDQADj3H2bzwwHVIXlQAiccm7r4xIQmjt_Oqm2FejWpBxLWs3L_RoUbharABi5FMnKnzmRL2TGju6UA4k'
};
var infowindow = new google.maps.InfoWindow();
var service = new google.maps.places.PlacesService(map);
service.getDetails(request, function(place, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
var marker = new google.maps.Marker({
map: map,
position: place.geometry.location
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent(place.name);
infowindow.open(map, this);
});
}
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
I can't figure out how to find the reference for my location.
Also, how would I get multiple values into
infowindow.setContent()
I found that if you use the textSearch() method, that it provides the illusive reference string. I wrote a client side script that uses the textSearch() method to provide the reference string for the getDetails() method here.
The long encrypted string is the Place reference, but it should only be used to go back and find the same place. Since it can change slightly it shouldn't be used to group ratings, check-ins, or other activity.
From the Places API documentation:
http://code.google.com/apis/maps/documentation/places/
"reference contains a unique token that you can use to retrieve
additional information about this place in a Place Details request.
You can store this token and use it at any time in future to refresh
cached data about this Place, but the same token is not guaranteed to
be returned for any given Place across different searches."
To add multiple values into the infowindow you just add what details you want show. Like this:
infowindow.setContent(place.name + address + rating);
var request
Is where there are setting their data for the locations. Looks to be fairly encrypted.

Resources