Wrong coordinates using HTML Geolocation API - html

I am trying to use HTML5 Geolocation API on Windows 10 using Chrome as a browser.
I am having problems with getting right longitude and latitude. I have tried also using some web applications such as where-am-i.me but it giving the same result. Only Google gives the right location. How I can fix this, can we use some Google API for this?
enter code here
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
$(".latitude").text(position.coords.latitude);
$(".longitude").text(position.coords.longitude);
showMap(position.coords.latitude, position.coords.longitude);
}

Related

How to simulate Geolocation service AS3

I'm creating an app that is using Geolocation servioce on phone o send location/time data over the internet. And that is working just fine. Problem is that I cannot test it in Flashdevelop, cause Geolocation is not supported, so I have to upload every time new code and test it on phone. Is there any way to simulate Geolocation service in Flashdevelop? Or generally, on desktop PC?
Sorry for bothering ... I found out... quite simple answer was..
private function startLocating():void {
var myLat:Number=44.2343;
var myLong:Number=20.9432;
_geo = new Geolocation();
_geo.addEventListener(GeolocationEvent.UPDATE, Handler1 );
if (Geolocation.isSupported) {
if (!_geo.muted) {
_geo.setRequestedUpdateInterval(1000);
} else {
trace ("Location service not turned on.");
}
} else {
/* this code is working when Geolocation is not supported */
_geo.dispatchEvent(new GeolocationEvent(GeolocationEvent.UPDATE,false,false,myLat,myLong));
}
}
private function Handler1(ev:GeolocationEvent):void {
var latitude:Number = ev.latitude;
var longitude:Number = ev.longitude;
.....
}

Geolocation in Windows Phone HTML App not working

I'm developing html5 windows phone 8 application and I've run into problem: geolocation doesn't work for me. I have WebBrowser.IsGeolocationEnabled property set to true and in app manifest ID_CAP_LOCATION is also checked. Hovewer even with the geolocation code copy-pasted from various HTML5 learning portals I'm still getting an error telling that site doesn't have geolocation permission.
Thanks for any help
var watchId = navigator.geolocation.watchPosition(scrollMap, handleError);
function scrollMap(position) {
myLoc.setLatLng([position.coords.latitude, position.coords.longitude]);
}
function handleError(error) {
myLoc.setLatLng([0, 0]);
}
I had the same issue, but solved it by totally rewriting my code - simplifying it:
var lng, lat;
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
}
else { alert("Geolocation is not supported by this browser."); }
}
function showPosition(position) {
alert("Latitude: " + position.coords.latitude +
"\nLongitude: " + position.coords.longitude);
lng = position.coords.longitude;
lat = position.coords.latitude;
}

HTML5 geolocation won't work in Firefox, Chrome and Chromium

I'm trying to use the HTML5 geolocation API; but I have problems to make it work on Firefox Chrome and Chromium :
init();
function init() {;
// Get the current location
getPosition();
}
function getPosition() {
navigator.geolocation.getCurrentPosition(success, fail,{
enableHighAccuracy:true,
timeout:10000,
maximumAge:Infinity
});
}
function success(position) {
alert("Your latitude: " + position.coords.latitude + "longitude: "
+ position.coords.longitude);
}
function fail(e) {
alert("Your position cannot be found"+e.code+" => "+e.message);
}
In IE9 and Safari it works flawlessly; but :
in Firefox (v13 and V14) there is an error code 3 (timeout)
in Chrome and Chromium (v20 and v21) there is and error code 2 with the message "Network location provider at 'https://maps.googleapis.com/maps/api/browserlocation/json?browser=googlechrome&sensor=true' : Response was malformed."
I have a fresh install of Chrome (installed today on windows XP, no extensions) and I have authorized the geolocation in the browser.
You can try it there :
http://jsfiddle.net/mhj82/38/
Is there a solution to make it work on all browser supporting geolocation ?
Have you read this ?
http://code.google.com/p/chromium/issues/detail?id=41001
At the end of the thread they come to the conclusion that in order to work in Chrome, geolocation must be performed on a device with a working wifi adapter.
Was wifi enabled on your computer ?
(dunno for firefox)
I have to wait until the document is loaded to get it work in chrome
jQuery().ready(function() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition....
}
});
Try this tested in chrome desktop and mobile
if (navigator.geolocation) {
var latitude = null;
var longitude = null;
navigator.geolocation.getCurrentPosition(function (position) {
latitude = position.coords.latitude;
longitude = position.coords.longitude;
});
} else {
alert("Geolocation API is not supported in your browser");
};

HTML5 Geolocation for IE8 and Mobile Browsers

So I have been developing a web application, and I have implemented the HTML5 geolocation feature. I have implemented this using Javascript code taken from Google's website, that interacts with the Google Map that I have on my page as well. Here is the code below:
// Note that using Google Gears requires loading the Javascript
// at http://code.google.com/apis/gears/gears_init.js
var initialLocation;
var siberia = new google.maps.LatLng(60, 105);
var newyork = new google.maps.LatLng(40.69847032728747, -73.9514422416687);
var browserSupportFlag = new Boolean();
function initialize() {
var myOptions = {
zoom: 6,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
// Try W3C Geolocation (Preferred)
if(navigator.geolocation) {
browserSupportFlag = true;
navigator.geolocation.getCurrentPosition(function(position) {
initialLocation = new google.maps.LatLng(position.coords.latitude,position.coords.longitude);
map.setCenter(initialLocation);
}, function() {
handleNoGeolocation(browserSupportFlag);
});
// Try Google Gears Geolocation
} else if (google.gears) {
browserSupportFlag = true;
var geo = google.gears.factory.create('beta.geolocation');
geo.getCurrentPosition(function(position) {
initialLocation = new google.maps.LatLng(position.latitude,position.longitude);
map.setCenter(initialLocation);
}, function() {
handleNoGeoLocation(browserSupportFlag);
});
// Browser doesn't support Geolocation
} else {
browserSupportFlag = false;
handleNoGeolocation(browserSupportFlag);
}
function handleNoGeolocation(errorFlag) {
if (errorFlag == true) {
alert("Geolocation service failed.");
initialLocation = newyork;
} else {
alert("Your browser doesn't support geolocation. We've placed you in Siberia.");
initialLocation = siberia;
}
map.setCenter(initialLocation);
}
}
So what this code does is, it checks to see if the browser you are accessing the site from supports the new WC3 geolocation features, and if it does, it uses that to find latitude and longitude. If you do not support it, it tries to use Google Gears to obtain that information, and finally, if you support neither, it bails out.
I am completely fine with using this the way it is for browsers like Firefox, Safari, Opera, and Chrome, because most new versions (and even some older ones), support these features, however, IE8 (9 works), doesn't :(
IE8 doesn't even use the Google Gears failsafe, it just doesn't work at all. Is there anyway (free like the above code), to use some form of geolocation on IE8, even if it's not as accurate to obtain latitude and longitude so I can plug it into the map?
Also, I haven't testing it yet but, if you were to log onto this site using a Mobile Browser (on the major devices), would it support WC3 Geolocation/Google Gears as well, or would it bonk out like IE8 does. I know I can also use the sensor=true attribute when requesting location if coming from a mobile device if they have their GPS turned on, so that's another way to do it, but I'd rather just use geolocation if they support it.
Thanks guys.
I am waiting for the HTML5 geolocation features to mature a bit more before I begin using them in full swing. In the mean time, I've used the APIs and datasets offered by MaxMind with great success.
Edit:
I forgot to mention, this sometimes doesn't work well with mobile browsers, so you may still want to use the HTML5 geolocation feature there as I've found it to be much more quick and reliable on mobile browsers.

How to let user point their position in my Google maps application?

I want let user mark their position in our google maps application and then save it to our database, then it can be showed in our google maps application in the next time.
If you want to save the position where the user clicked you can use a "click" listener to get the latitude and longitude of the click with code like this then send it to your server using an Ajax style call where it can be stored in the database.
var clickListener = GEvent.addListener(map,"click",
function (overlay,latlng,overlaylatlng) {
alert(latlng);
});
This code is for v2 of the Google Maps API. Version 3 should have something similar.
An options is to try geolocation first and let the browser pinpoint them. If the browser doesn't support geolocation or an error occurs you can fall back onto them manually adding their position.
var geolocation = null; // holds the latlng object
navigator.geolocation.getCurrentPosition( geolocation_success_init, geolocation_error_init, {enableHighAccuracy: false, timeout: 10000} );
function geolocation_success_init( position ) {
geolocation = new google.maps.LatLng(position.coords.latitude,position.coords.longitude);
initialize_map();
}
function geolocation_error_init( error ){
initialize_map();
}
when you create your map check for geolocation
if ( geolocation ) {
marker = new google.maps.Marker({
position: geolocation,
map:.map,
title: "Your Location"
});
}