How to get Latitude + Longitude = city name, in electron js.
While I have already Google Api Key
How to get Latitude + Longitude = city name, in electron js.
While I have already Google Api Key
Related
So I tried geocode but it can only find the users location based on ip addresses but I need the exact lat and long values of the user. Btw what is the accuracy of the ip address method.
Ask the user on the client side for Geolocation permissions. You'll get the coordinates directly and you don't have to geocode anything. If the user doesn't give you the permission you shouldn't trying to locate them anyway.
Simple JS example:
var x = document.getElementById("demo");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
// Do something with the coordinates
x.innerHTML = "Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude;
}
More information here.
You could use the Google GeoCode API but after 2000 requests, you would need to pay for it. This works on the idea that you have the users address or even just a post code (Zip code).
In terms of detecting location from IP, pretty hard if not impossible. You can usually get a broad location (City, County or State) but not the actual house or street etc.
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'm trying to make a website thats simply shows your location and how you get to the location where you want to go.
To get my current location im using this code i found here on stack:
// Get the coordinates
navigator.geolocation.getCurrentPosition(show_map);
function show_map(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
// post to your controller
var url = "/Home/Index?latitude=" + latitude + "&longtitude=" + longitude;
$.post(url, function(data) {
});
}
I've breakpointed it and it does give me the coordinates for position.
But my problem is, how do I show how to get to point B(Point B will be hardcoded coordinates)?
I've looked into Google Directions API aswell as Distance Matrix API, and for a newbie like me the I find the documentation quite hard to understand. I'm trying to do this in an MVC 6 project, am I approaching this the wrong way? Should i keep looking at Google Directions API?
This can all be performed client side via the Google Maps API and their Direction Service. Have you seen this -> https://developers.google.com/maps/documentation/javascript/examples/directions-simple
i want to get the user location information like city, area etc using html5 geolocation,i tried the below article but with that im getting latitude and longitude, i want to get the city and area information,
http://www.dotnetcurry.com/ShowArticle.aspx?ID=782
When you have the location of the user, you'll need to do a reverse geocoding to get information about the location such as city, etc.
Have a look at the reverse geocoding API for Google Maps.
navigator.geolocation.getCurrentPosition(function(pos){
var latlng = new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude);
geocoder.geocode({'latLng': latlng}, function(results, status) {
console.log(results);
// Analyze results and find the info you need.
});
});
Check out How to reverse geocode without Google for information about geocoding without using Google Maps.
I'm using twitter4j to get the location of a Twitter user:
Twitter twitter = new TwitterFactory().getInstance();
twitter.setOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET);
long id = accessToken.getUserId();
User user = twitter.showUser(id);
System.out.print("LOCATION: " +user.getLocation());
user.getLocation() does not include the country. How to get the user's country using twitter4j?
There's no separate field for a user's country. Whatever information is set in the Location field on your Twitter Profile page should be returned by the getLocation() method.
One thing I noticed about your code is that you're not showing how the accessToken variable is initialized. Try the following:
Twitter twitter = new TwitterFactory().getInstance();
long id = new AccessToken(ACCESS_TOKEN, ACCESS_TOKEN_SECRET).getUserId();
User user = twitter.showUser(id);
System.out.print("LOCATION: " + user.getLocation());
Where ACCESS_TOKEN and ACCESS_TOKEN_SECRET are the values you get after granting your application permission to access your Twitter account on your Twitter Developers page. When I run the code above I get the expected: "LOCATION: Charlotte, NC USA"