? marks coming from reverse geocoded response
So someone from Russia made a reverse geocoding response from my website. I parse the Json and concatenate city and state into one string on the client side. This is what that concatenated string ended up being:
???? ?????-?????????, ??????
Is there any situation where Google would send ? marks back through Json from a reverse geocoded response? The latitude/longtitude were correct. When I made the same Json post directly through my browser I got a correct response:
http://maps.googleapis.com/maps/api/geocode/json?latlng=60.0486851,30.3197483&sensor=true
Anyone have any ideas?
Could it be because I am accessing the Json from the USA, and he was accessing it from Russia?
EDIT: Concatenation happens here:
First I get the results:
geocoder.geocode({'latLng': realUsersLoc}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[1]) {
var loc = getCityState(results);
function getCityState(results)
{
var city = '';
var state = '';
var bad = '';
var good = '';
var us = true;
// check for non-us
for (var i = 0; i < results[0].address_components.length; i++)
{
var shortname = results[0].address_components[i].short_name;
var longname = results[0].address_components[i].long_name;
var type = results[0].address_components[i].types;
if (type.indexOf("country") != -1)
{
if (!isNullOrWhitespace(shortname))
{
us = (shortname == 'US');
}
else
{
us = (longname == 'United States');
}
}
}
if (!us)
{
for (var i = 0; i < results[0].address_components.length; i++)
{
var shortname = results[0].address_components[i].short_name;
var longname = results[0].address_components[i].long_name;
var type = results[0].address_components[i].types;
if (type.indexOf("country") != -1)
{
if (!isNullOrWhitespace(longname))
{
state = longname;
}
else
{
state = shortname;
}
}
if (type.indexOf("administrative_area_level_1") != -1)
{
if (!isNullOrWhitespace(shortname))
{
city = shortname;
}
else
{
city = longname;
}
}
else if (type.indexOf("locality") != -1)
{
if (!isNullOrWhitespace(shortname))
{
city = shortname;
}
else
{
city = longname;
}
}
}
}
else
{
// us
for (var i = 0; i < results[0].address_components.length; i++)
{
var shortname = results[0].address_components[i].short_name;
var longname = results[0].address_components[i].long_name;
var type = results[0].address_components[i].types;
if (type.indexOf("administrative_area_level_1") != -1)
{
if (!isNullOrWhitespace(shortname))
{
state = shortname;
}
else
{
state = longname;
}
}
else if (type.indexOf("locality") != -1)
{
if (!isNullOrWhitespace(shortname))
{
city = shortname;
}
else
{
city = longname;
}
}
else if (type.indexOf("administrative_area_level_3") != -1)
{
if (!isNullOrWhitespace(shortname))
{
good = shortname;
}
else
{
good = longname;
}
}
else if (type.indexOf("administrative_area_level_2") != -1)
{
if (!isNullOrWhitespace(shortname))
{
bad = shortname;
}
else
{
bad = longname;
}
}
}
if (city == '')
{
if (good != '')
{
city = good;
}
开发者_Python百科 else
{
city = bad;
}
}
}
if (isNullOrWhitespace(city) && isNullOrWhitespace(state))
{
return 'N/A';
}
if (isNullOrWhitespace(city))
{
return state;
}
else if (isNullOrWhitespace(state))
{
return city;
}
return (city + ', ' + state)
}
Considering the presence of the dash with the question marks, it seems exceedingly likely that this is a character set issue and not a case of Google sending back question marks. (How certain are you that your site is specifying UTF-8 as its charset?) If you don't care about internationalization, then you can work around the problem by forcing the results into English with the language
parameter in the URL (see below). This is, of course, not ideal, but may be acceptable for some uses.
In the likely event that the above workaround is not acceptable, try running your code with the results from http://maps.googleapis.com/maps/api/geocode/json?latlng=60.0486851,30.3197483&sensor=true&language=ru (note the language
parameter tacked on to the end to force it to return Russian-language data) on various browsers to see if you can replicate the question-mark problem. (If you know what browser/platform the user was using when they experienced the problem, all the better.)
Maybe the person's response was returned content in Cyrillic or some other language and your charset is not the proper one?
精彩评论