CodenameOne google maps - some markers not appearing - google-maps

Using the fantastic Native Google Maps cn1lib, I'm attempting to place markers on the map, first one representing the user, then another slew of them representing objects from my database. The first marker always plunks down fine, and I can relocate it (by erasing it and creating a new one in the new position), but the subsequent markers don't show on the map. I get no errors in the simulator or on an Android device, but on both the additional markers don't show. The code looks like this:
class MyClass{
LinkedList<MapContainer.MapObject> towerMarkers;
MapContainer towerMap;
public void displayTowers(ArrayList<HashMap<String,Object>> towers){
if(towerMarkers == null){
towerMarkers = new LinkedList<>();
}else{
for(MapContainer.MapObject marker: towerMarkers){
towerMap.removeMapObject(marker);
}
towerMarkers.clear();
}
for(HashMap<String, Object> obj: towers){
towerMarkers.add(towerMap.addMarker(EncodedImage.createFromImage(FontImage.createMaterial(
FontImage.MATERIAL_SETTINGS_INPUT_ANTENNA, cellTowerMarker, 3), false),
new Coord(Double.parseDouble((String)obj.get("latitude")), Double.parseDouble((String)obj.get("longitude"))),
"", "", null));
}
}
...
The code that works is very similar:
towerMap.addTapListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent evt) {
int x = evt.getX();
int y = evt.getY();
Coord tapCoord = towerMap.getCoordAtPosition(x, y);
if(myLocationMarker != null){
towerMap.removeMapObject(myLocationMarker);
}
myLocationMarker = towerMap.addMarker(EncodedImage.createFromImage(FontImage.createMaterial(FontImage.MATERIAL_LOCATION_ON, userLocationMarker, 4),
false), tapCoord, null, null, null);
findLongitudeField(f).setText(Double.toString(tapCoord.getLongitude()));
findLatitudeField(f).setText(Double.toString(tapCoord.getLatitude()));
findBtnUseChosenLocation(f).setEnabled(true);
}
});
The only odd thing that I noticed is when I inspect the map markers, they all (including the one that appears) seem to have coordinates in total different system. Instead of (35.789..., 32.1233...), they're more like (3897665.88999, 4277888.988884), but since the one that shows up is also like that, it doesn't seem to be a problem.
Any help will be appreciated!

Related

Changing texture depending on action

So when a user makes a purchase they get a new texture available that will replace the original one. I´ve sort of pulled it of. But I also want the user to ba able to replace back to the original one if the wish to do so.
At the moment the user makes a purchase and the texture changes fine. But as I store that change in preferences it makes it permanent. So when I try to press the button to change to the original stone, which simply calls "setStone(...)" , nothing happends.
Anyone that can see where I´ve gone wrong?
P.S the code is not copied straight of, just cut in the important parts.
ObjectMap<Integer, Texture> screenMap = new ObjectMap<Integer, Texture>();
ObjectMap<String, Boolean> mTexturesStatus = new ObjectMap<String, Boolean>();
public void setStone1() {
stoneImage = new Image(screenMap.get(0));
}
public void setStone(int screenId) {
stoneImage = new Image(screenMap.get(screenId));
}
screenMap.put(0, sdStone);
screenMap.put(1, stone_3);
mTexturesStatus.put("stone1", stone1);
mTexturesStatus.put("stone2", stone2);
btnArrow.addListener(new ChangeListener() {
#Override
public void changed(ChangeEvent event, Actor actor) {
game.setScreen(0);
//Saves the entered text.
Preferences prefs = Gdx.app.getPreferences("preferences");
prefs.putString("textField", textField.getText());
prefs.putString("textArea", textArea.getText());
prefs.getBoolean("stoneOne");
prefs.getBoolean("stoneTwo");
prefs.flush();
}
});
//screenMap.put(prefs.getInteger("stoneOne", 0), sdStone);
//screenMap.put(prefs.getInteger("stoneTwo", 1), stone_3);
setStone1();
if(stone1 = true) {
setStone(0);
prefs.putBoolean("stoneOne", true);
}
if(stone2 = true) {
setStone(1);
prefs.putBoolean("stoneTwo", true);
}
}

Binding doesn't work in MVVM in WP8

I am new in the development of WP8. I have been following a online course for a couple of weeks and the second task of the course was to develop a app to show the weather, some news and photos related to the city.
So far, I have develop the app following the MVVM pattern using the Panorama control as the conteiner for the differents contents I need to show.
To no longer this, the problem I facing is at the moment to display the xml data that is retrieve from the webservices.
The XAML is:
<phone:panorama x:Name="myPanorama"
DataContext = {Binding Source="WeatherViewModel"}>
<PanoramaItem header="MyWeather">
<Textblock x:name="txtCity"
Text = {Binding Weather.City}
</Textblock>
</PanoramaItem>
<panoramaItem header="Config">
<Text x:Name="txtGetCity"/>
<Button x:Name="btnGetCity"
Command={Binding GetWeatherCommand}/>
</panoramaItem>
</phone:panorama>
My ViewModel:
public class WeaterViewModel : NotificationEnableObject
{
private Weather _currentWeather;
public Weather GetCurrentWeather
{
get
{
if (_currentWeather == null)
_currentWeather = new Weather();
return _currentWeather;
}
set { _currentWeather = value;
OnPropertyChanged("GetCurrentWeather");
}
}
//Constructor ServiceModel serviceModel = new ServiceModel();
public WeatherViewModel()
{
serviceModel.GetWeatherCompleted += (s, a) =>
{
_currentWeather = new Clima();
_currentWeather.City= a.Results[0].City;
_currentWeather.tempC = a.Results[0].tempC;
};
getWeatherCommand = new ActionCommand(null);
}
ActionCommand getWeatherCommand; // ActionCommand derivied from ICommand
public ActionCommand GetWeatherCommand
{
get
{
if (getWeatherCommand!= null)
{
getWeatherCommand = new ActionCommand(() =>
{
//Call the Service who retrieved the data
});
}
return getWeatherCommand;
}
}
}
The Weather specified is a public class which contain the City property. I have tried using an IObservableCollention as well howerver, the result is the same :-(
As you can see in the panorama control I have 2 sections. The one where I write the city I wanna see and the section where I show the information I get from the web services.
Any clue, or help would be very appreciate
Regards!
Ok, I think that is an easy fix.
You're setting GetCurrentWeather this way:
_currentWeather = new Clima();
_currentWeather.City= a.Results[0].City;
_currentWeather.tempC = a.Results[0].tempC;
This is not firing the PropertyChanged event. Change it to:
GetCurrentWeather= new Clima();
GetCurrentWeather.City= a.Results[0].City;
GetCurrentWeather.tempC = a.Results[0].tempC;
and you should be fine.

google map load map using internet or gps

I want to use google map v2 to load the map using either gps or internet, I can do it using just internet.
when I connect my application to internet, the map is loaded successfully, but if i used just gps the map doesn't show even though I have already activiate the gps in my phone and in my app.
this is my code, first i get my location then i load the mapp
setContentView(R.layout.google_map_layout);
locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
boolean enabled = locationManager
.isProviderEnabled(LocationManager.GPS_PROVIDER);
if (!enabled) {
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(intent);
} else {
Criteria criteria = new Criteria();
provider = locationManager.getBestProvider(criteria, false);
Location location = locationManager.getLastKnownLocation(provider);
if (location != null) {
Toast.makeText(RestaurantsNearBy.this,
location.getLatitude() + "", Toast.LENGTH_LONG).show();
LatLng currentLocation = new LatLng(location.getLatitude(),
location.getLongitude());
new getRestaurantNearBy().execute(currentLocation.latitude,
currentLocation.longitude);
map = ((SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map)).getMap();
map.setInfoWindowAdapter(new InfoWindowAdapter() {
private final View window = getLayoutInflater().inflate(
R.layout.restaurant_marker, null);
#Override
public View getInfoWindow(Marker marker) {
return null;
}
#Override
public View getInfoContents(Marker marker) {
TextView tv_title = ((TextView) window
.findViewById(R.id.tv_title));
TextView tv_description = ((TextView) window
.findViewById(R.id.tv_description));
ImageView iv_image = ((ImageView) window
.findViewById(R.id.iv_image));
AddressMap oneAddres = markersMap.get(marker);
tv_title.setText(oneAddres.getRestaurant().getName());
tv_description.setText(oneAddres.getDescription());
Restaurant r = markersMap.get(marker).getRestaurant();
if (Restaurant.getRestaurant(r.getID()) != null) {
if (Restaurant.getRestaurant(r.getID()).getImage() != null) {
iv_image.setImageBitmap(Restaurant
.getRestaurant(r.getID()).getImage());
} else {
try {
iv_image.setImageBitmap(r
.getImageFromWebService());
} catch (Exception e) {
iv_image.setImageResource(R.drawable.unknown);
}
}
} else {
iv_image.setImageBitmap(r.getImageFromWebService());
}
return window;
}
});
map.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
#Override
public void onInfoWindowClick(Marker marker) {
final AddressMap oneAddress = markersMap.get(marker);
AlertDialog alertDialog3 = new AlertDialog.Builder(
RestaurantsNearBy.this).create();
alertDialog3.setTitle("Order !");
alertDialog3
.setMessage("Do you want to order from the restaurant "
+ oneAddress.getRestaurant().getName());
alertDialog3.setIcon(R.drawable.more_information);
alertDialog3.setButton("Yes",
new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog,
int which) {
Basket.setRestaurant(oneAddress
.getRestaurant());
dialog.dismiss();
Intent addAddressIntent = new Intent(
RestaurantsNearBy.this,
OrderMeal.class);
startActivity(addAddressIntent);
}
});
alertDialog3.setButton2("No",
new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog,
int which) {
dialog.dismiss();
}
});
alertDialog3.show();
}
});
// Move the camera instantly to hamburg with a zoom of 15.
map.moveCamera(CameraUpdateFactory.newLatLngZoom(
currentLocation, 15));
// Zoom in, animating the camera.
map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
Log.d("Provider ", provider + " has been selected.");
onLocationChanged(location);
} else {
Toast.makeText(RestaurantsNearBy.this, "Sorry we couldn't define your location",
Toast.LENGTH_SHORT).show();
}
}
You should use proper tags, Google Maps can be found on loads of platforms, and you have a question about the android versions, so at least add Android tag.
On the question: Google Maps NEEDS active internet connection, when you first load the maps. V2 does some decent caching on your SD card (sometimes a bit excessive too), allowing you to later check thoose already loaded maps offline, but the principle is: no active internet connection, no Google Maps.
ps: GPS is NOT an internet connection.
By default you can't load the map data properly if you aren't connected with wifi or mobile connection. GPS only lets you find your position.

How to implement google maps to search by street name, city?

I need search functionality like this site. But I am wondering how can I get coordinates from google api by street name?
Google Geocoding API
You can enter in an address and it will return the Lat/long co-ordinates in a Json response or XML etc
You can read about it here:
http://code.google.com/apis/maps/documentation/geocoding/
In the onclick event of search write
List<Address> addresses = geoCoder.getFromLocationName("enter location name",5);
p = new GeoPoint( (int) (addresses.get(0).getLatitude() * 1E6),
(int) (addresses.get(0).getLongitude() * 1E6));
controller.animateTo(p);
controller.setZoom(12);
MapOverlay mapOverlay = new MapOverlay();
List<Overlay> listOfOverlays = map.getOverlays();
listOfOverlays.clear();
listOfOverlays.add(mapOverlay);
map.invalidate();
Then create map overlay class in mapActivity
class MapOverlay extends Overlay
{
private GeoPoint pointToDraw;
public void setPointToDraw(GeoPoint point) {
pointToDraw = point;
}
public GeoPoint getPointToDraw()
{
return pointToDraw;
}
#Override
public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) {
super.draw(canvas, mapView, shadow);
// convert point to pixels
Point screenPts = new Point();
mapView.getProjection().toPixels(pointToDraw, screenPts);
// add marker
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.marker);
canvas.drawBitmap(bmp, screenPts.x, screenPts.y - 24, null); // 24 is the height of image
return true;
}
}

BlackBerry and map based apps like Yelp and Google Map

This is a question-loaded post from someone who is just getting started with BB development. Any guidance is much appreciated.
How are map based BlackBerry apps such as Yelp and Google Map implemented? As with the web based version. Yelp for the BB allows you to search for restaurants & etc. based on on the current or specified location. The search result is in a form of a list or a map view displaying markers of the search results. Yelp's map is powered by Bing. How is the map, along with the markers, invoked within the BB code? For the list view, what is being used to retrieve the list of results from the database. Can any database be used?
Google Map 3.2 for the BB now supports layers. Again, how are the Google maps invoked? You can also select a marker (i.e. Wiki, gas station) of a particular location directly on the map and view the information of that location (i.e. Wiki, gas station address). How is this being done?
My knowledge in map technology as well as BB development is very limited, so basic or in depth feedback are both welcomed.
I have no experience of writing real-world gps applications for blackberry, below are just my observations and thoughts about possible workarounds.
Blackberry Yelp Application
Indeed, Blackberry Yelp application show map if you do search and then go into result and see Map Adress
alt text http://img197.imageshack.us/img197/965/13428830.jpgalt text http://img269.imageshack.us/img269/1976/92068364.jpg
See also Yelp Launches Bing-Powered Blackberry App
If you look into Yelp API you will find only search functionality which may optionally use Google Maps to display search result location on your website.
Bing seems to be MS analogue for Google Maps. And there is an ASP Bing Map Control which hardly can be used in BB development.
Blackberry Google Maps Application
alt text http://img193.imageshack.us/img193/9678/39917026.jpg
You can invoke installed Google Maps Mobile from code:
class Scr extends MainScreen {
public Scr() {
}
protected void makeMenu(Menu menu, int instance) {
super.makeMenu(menu, instance);
menu.add(mInvokeGMaps);
}
MenuItem mInvokeGMaps = new MenuItem("Run GMaps", 0, 0) {
public void run() {
GMLocation location
= new GMLocation(51.507778, -0.128056, "London");
invokeGMaps(location);
};
};
public void invokeGMaps(GMLocation l) {
int mh = CodeModuleManager.getModuleHandle("GoogleMaps");
if (mh == 0) {
try {
throw new ApplicationManagerException(
"GoogleMaps isn't installed");
} catch (ApplicationManagerException e) {
System.out.println(e.getMessage());
}
}
URLEncodedPostData uepd = new URLEncodedPostData(null, false);
uepd.append("action", "LOCN");
uepd.append("a", "#latlon:" + l.getLatitude()
+ "," + l.getLongitude());
uepd.append("title", l.getName());
uepd.append("description", l.getDescription());
String[] args = { "http://gmm/x?" + uepd.toString() };
ApplicationDescriptor ad = CodeModuleManager
.getApplicationDescriptors(mh)[0];
ApplicationDescriptor ad2 = new ApplicationDescriptor(ad, args);
try {
ApplicationManager.getApplicationManager()
.runApplication(ad2, true);
} catch (ApplicationManagerException e) {
System.out.println(e.getMessage());
}
}
}
Using custom location class:
class GMLocation {
String mName;
String mDescription;
double mLatitude;
double mLongitude;
public GMLocation(double lat, double lon) {
mLatitude = lat;
mLongitude = lon;
}
public GMLocation(double d, double e, String name) {
this(d, e);
mName = name;
}
public GMLocation(double lat, double lon, String name, String descr) {
this(lat, lon, name);
mDescription = descr;
}
public String getName() {
return mName;
}
public String getDescription() {
return mDescription;
}
public String getLongitude() {
return String.valueOf(mLongitude);
}
public String getLatitude() {
return String.valueOf(mLatitude);
}
}
See also How to use Google Map in Blackberry application?
Conclusion
Blackberry browser and BrowserField has a limited support of JavaScript. Since both Bing and GMaps are based on JavaScript, my suspicion is that they use static images retrieved from server to display map control. This may be possible but that means server side implementation and all required API developer keys.
As an alternative, you can invoke installed GMaps from code on Blackberry.