0

I know there are more accurate geolocation methods, but I want to have it transparent to the user rather than ask them to "allow".
I am using a very simple method and it works great on most of the computers I have tried, but on some such as my grandmothers laptop with IE7 I think and Windows XP, as well as a friends MAC, it did not work.
I figured that even if the location database came up empty, the else statement should fill in for New York, no?

What am I missing? thanks.

<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">// <![CDATA[
if (typeof(google.loader.ClientLocation.address.city) != null) {
  document.write(google.loader.ClientLocation.address.city);
} else {
  document.write("New York");
}
// ]]>
</script>

Edited by raredesign: n/a

4
Contributors
7
Replies
8
Views
5 Years
Discussion Span
Last Post by chrislim2888
0

what value are you getting in those cases?

typeof(google.loader.ClientLocation.address.city)

maybe its some invisible char or who knows

also check out if

document.write("New York");

works at all (force the if statement call else by adding to the check that value would be false)

0

I just posted this on the joomla forums, since I am using version 1.7. It is possible that the editor is messing up the javascript. It is moving the closing script tag </script> to the line that includes // ]]>
This likely invalidates the code since it comments out the script tag.

// ]]></script>

I am not positive yet, but we will see. I am trying to find out how to stop it from modifying the code first.

0

what value are you getting in those cases?
typeof(google.loader.ClientLocation.address.city)
maybe its some invisible char or who knows
also check out if
document.write("New York");
works at all (force the if statement call else by adding to the check that value would be false)

I set != to == and the else fell right into place and worked, so I am still not sure why it would come up empty in some cases.

0

I know there are more accurate geolocation methods, but I want to have it transparent to the user rather than ask them to "allow".
I am using a very simple method and it works great on most of the computers I have tried, but on some such as my grandmothers laptop with IE7 I think and Windows XP, as well as a friends MAC, it did not work.
I figured that even if the location database came up empty, the else statement should fill in for New York, no?

What am I missing? thanks.

<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">// <![CDATA[
if (typeof(google.loader.ClientLocation.address.city) != null) {
  document.write(google.loader.ClientLocation.address.city);
} else {
  document.write("New York");
}
// ]]>
</script>

your conditional is wrong if (typeof(google.loader.ClientLocation.address.city) != null) { try it with:

if ( typeof( google.loader.ClientLocation.address.city ) ) {...

instead.

! Nope, this wont work either! You'll need my special exists() method instead.

Edited by Troy III: n/a

0

I think it might be Apple's and old browsers that are causing the problem.

Any idea how to get this working on a MAC?

0

I think it might be Apple's and old browsers that are causing the problem.

Any idea how to get this working on a MAC?

I think it was google's db that was causing the problem. I just switched to maxmind and i think it works.

0

Is your visitor click 'allow' and grant you the approval to read their location? The problem with this technique was it require explicit approval from your visitor, if your visitor refuse to do so, you won't have any result display.

The better solution would be checking their location using geo database or web service, such as http://www.ipinfodb.com (free) or http://www.ip2location.com (paid).

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.