I want to create a JSON file to style my google map but I get this message: E/Google Maps Android API: Map style parsing failed: org.json.JSONException: Value res of type java.lang.String cannot be converted to JSONArray
E/MapsActivityRaw: Style parsing failed. Any help?
Here is my code example where I have the method with JSON creation and on left side you see the raw package where the JSON file
Here is the error that I get
I used Google platform mapstyle.withgoogle.com. But the thing that I'm not sure about, that I created a Text Document then changed the ending to .json, copied the JSON code from google platform and put it there and then copied the file and put it in android studio. Because I couldn't know how to create a JSON file in android studio. I don't know if it sounds the right way to do that?
in the previous comment that I left you, it was because I did not have the solution, but in reviewing the google documentation well I realized that there are two types of codes to implement the styles, one by JSON files and others by means of string
For the code that you show in the image it has to have a style_gray string resource, for this case I would suppose that you would have an xml file or that variable in the string.xml, you could use that same code like this:
googleMap.setMapStyle(new MapStyleOptions(getResources().getString(R.raw.map_style_aubergine)));
For that error to be solved, you would have to implement this other code, which if it is compatible with JSON files in the format generated by https://mapstyle.withgoogle.com/, the code would be the following:
googleMap.setMapStyle(MapStyleOptions.loadRawResourceStyle(this,R.raw.map_style_aubergine));
In my case the map_style_aubergine is the JSON file and a variable in the string.xml you can use this as an example and make the respective corrections in your code
Related
What I have been trying to do, is to use a XML file to access a array of data that I wish to have stored on the web. The file looks like this:
<resources>
<60020> 13.5 </60020>
<50020> 11.2 </50020>
</resources>
The program grabs the user's GPS coordinates and then geocodes them to a zip code, that part I have down. What I wished to do after that, was to compare that zip code to the zip codes in the XML file and then return a integer based on the closest zip code. For instance, if the user has zip code 60013, then the program would see that 60020 is the closest zip code, and then return 13.5 based on that search.
I have already tried making a SAXParser, and I can return the first value, however, I cannot how to force the SAXParser to read through the whole document to find the nearest value. I also already have a algorithm to find the nearest value (simple for loop checking for difference in values), but again, I am stuck on the whole idea of how to check the whole list of values. Am I using the wrong type of storage method? Should I be using SQL? Or a different parser?
Thanks for your help.
I better idea would be to round off the zip code first and then search it in the XML file.
I would recommend Xpath Api for querying the XML file.
I very good tutorial about Xpath can be found here
http://www.ibm.com/developerworks/library/x-javaxpathapi/index.html
and as SAXparser itself will look for tags, it won't roundoff them, allover XPath is more prefered for searching XML documents, as it is relatively easy.
Hi I have created xml where i need to pass file name and sent to server. It is working fine. But when the file name contains special character the name looks different in xml. similarly in reading same problem occurred. eg if file name is ♥♣◘• then i cant send the exact in xml also i cant read as it is from xml. How to resolve this type of issue. Whether i need to set any parameters in xml?
Thanks
Sunil Kumar Sahoo
Seems you have en ENCODING problem... Try out a few like UTF16 or UTF32... I know there are some issues in Android 'bout encoding stuff, you never really know what you get except if you FORCE it !
Try then using stuffs like :
String(byte[] data, String charsetName)
Converts the byte array to a string using the named charset.
with charsetname such as "UTF-8" or "UTF-16".
I have xml file in server. I am parsing this xml using DOM(xml is not big). In one node there is string with double quotes.
<NODE1>hello "world"</NODE1>
When i see this xml url in browser and check its source it looks like this:
<NODE1>hello "world"</NODE1>
So when i parse this value i get string till double quotes. It seems after double quotes parser doesn't go forward. Any help ? I want to use DOM only in my current situation. This xml is used by other platform also apart from android. Like in iPhone its working perfectly. What should I do to read all value in android using DOM.
Thanks.
I'm not sure if I understand your question, but have a look at using CDATA
http://www.globalguideline.com/xml/XML_CDATA.php
A xml that contains double quote in a value is not valid according to specification: http://www.devx.com/tips/Tip/14068. I would suggest that you escape the special characters server side otherwise you will not be able to parse the xml.
I want to parse a JSON file generated by my RESTful application and use values from that file in order to change some variables of the layout/style.xml like the color of the background. I really need some help with it.
If you want to convert your JSON file to java objects you can use gson (http://code.google.com/p/google-gson/). On the other hand the layout/style.xml file cannot be modified in run-time. If you want to change the background color or any other UI property in run-time you have to do it programatically. For example you can define all the necessary styles in your layout/style.xml and when you converted your JSON file into java objects with gson, you can apply the corresponding style depending on the JSON response.
I'm new to Android Development, I have to parse my XML files through Http request, i'm using this example for parsing
http://www.androidhive.info/2011/11/android-xml-parsing-tutorial/
which works fine for me in all the the XML file through HTTPRequest except the one which having CADATA like:-
<title> <![CDATA[ Timer for work ]]> </title>
When i'm trying to parse this file which having this type of data i'm not getting any thing on the ListView.
This file having 10 new after parsing it shows only 10 cells but not showing any data but when i parse other XML file which not having this kind of CADATA type data that works fine showing text .
Can any one plz suggest me how to rectify this problem of CADATA in parsing XML.
Thanks In Advance
You probably need to know that LexicalHandlers exist. You get callbacks of startCDATA() endCDATA()