BlackBerry and map based apps like Yelp and Google Map - google-maps

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.

Related

Display store location via map pin in xamarin form

I want to expound the title. Currently we are making our thesis/project.
We have 2 platforms. Web and mobile.
In our web, we have functionality/feature that admin can insert data of store into database, example fields are name of the store, their products and the LOCATION OF that store.
I am assign in our mobile, one of the functionality is map. I have this UI
That red circle is the parameter of our location or limitation or let say NEARBY ME and the PINS assuming those are the store who subscribes in our system, that's my expected output.
This is what I've done in my tab view "map" with map.
my map xaml
<maps:Map
x:Name="myMap"
MapType="Hybrid"
IsShowingUser="True"
/>
map.xaml.cs
public MapPage()
{
InitializeComponent();
DisplayCurrentLocation();
// this.AddMarkerInCurrentLocation();
}
public async void DisplayCurrentLocation()
{
try
{
var request = new GeolocationRequest(GeolocationAccuracy.Medium);
var location = await Geolocation.GetLocationAsync(request);
if (location != null)
{
Position p = new Position(location.Latitude, location.Longitude);
MapSpan mapSpan = MapSpan.FromCenterAndRadius(p, Distance.FromKilometers(.444));
myMap.MoveToRegion(mapSpan);
}
}
catch(FeatureNotSupportedException fnsEx)
{
}
catch
(FeatureNotEnabledException fneEx)
{
}
catch(Exception ex)
{
}
}
Any link's solution that are related to my post, kindly comment it and Im glad to study the article. Thank you in advance.
Display store location via map pin in xamarin form
If you have obtained the location(Latitude, Longitude) of the stores, you can do this:
List<Location_Store> Location_Stores =new List<Location_Store>();
// Add the location of stores to List
Location_Stores.add(...);
foreach (var item in Location_Stores)            
{                
Pin pin = new Pin                
{                    
Label = item.StoreName,                    
//Address = "The city with a boardwalk",                    
Type = PinType.Place,                    
Position = new Position(item.Latitude,item.Longitude)               
};                
myMap.Pins.Add(pin);            
}
Location_Store.cs:
public class Location_Store    
{        
public string StoreName { get; set; }        
public double Latitude { get; set; }        
public double Longitude { get; set; }
...    
}
For more information about how to display location by pin in Xamarin Forms, you can refer to Xamarin.Forms Map Pins.

CodenameOne google maps - some markers not appearing

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!

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.

Embedded Google Map can't get current location in WebView

I followed this tutorial: http://android-er.blogspot.com/2013/03/embed-google-map-in-webview.html
I'm trying to just use the Google Map in the WebView, but it can't get my current location. I've enabled JavaScript on the WebView. What else do I have to enable?
Does anyone know why that might be? Shouldn't it prompt me to use my current location?
Note that I am not interested in using a MapView as an alternative whatsoever. I'm trying to find out what I need to set on the WebView or maybe on the device's location services?
You should permit the web view to access your location by overriding the method onGeolocationPermissionsShowPrompt like this:
webView.setWebChromeClient(new WebChromeClient(){
#Override
public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) {
callback.invoke(origin, true, false);
}
});
On API 5.x and below, you will need
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
in your AndroidManifest.xml.
But to allow permissions for geolocation on API 6.0+, you have to request the permission at runtime.
To do this, use
private String mGeolocationOrigin;
private GeolocationPermissions.Callback mGeolocationCallback;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// other setup
myWebView.setWebChromeClient(new MyWebChromeClient());
}
private WebChromeClient mWebChromeClient = new WebChromeClient() {
#Override
public void onGeolocationPermissionsShowPrompt(String origin,
GeolocationPermissions.Callback callback) {
// Geolocation permissions coming from this app's Manifest will only be valid for devices with API_VERSION < 23.
// On API 23 and above, we must check for permission, and possibly ask for it.
final String permission = Manifest.permission.ACCESS_FINE_LOCATION;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M ||
ContextCompat.checkSelfPermission(MainActivity.this, permission) == PackageManager.PERMISSION_GRANTED) {
// we're on SDK < 23 OR user has already granted permission
callback.invoke(origin, true, false);
} else {
if (ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this, permission)) {
// user has denied this permission before and selected [/] DON'T ASK ME AGAIN
// TODO Best Practice: show an AlertDialog explaining why the user could allow this permission, then ask again
} else {
// ask the user for permissions
ActivityCompat.requestPermissions(MainActivity.this, new String[] {permission}, RP_ACCESS_LOCATION);
mGeolocationOrigin = origin;
mGeolocationCallback = callback;
}
}
}
}
and receive the result:
#Override
public void onRequestPermissionsResult(int requestCode, #NonNull String[] permissions, #NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
switch (requestCode) {
case RP_ACCESS_LOCATION:
boolean allow = false;
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// user has allowed these permissions
allow = true;
}
if (mGeolocationCallback != null) {
mGeolocationCallback.invoke(mGeolocationOrigin, allow, false);
}
break;
}
}
in your activity.
You can try GreenDroid with Google Maps.
Checkt it out: https://github.com/cyrilmottier/GreenDroid
You'd have to enable android.permission.ACCESS_FINE_LOCATION and android.permission.INTERNET,
Create a LocationManager instance and LocationListener instance
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
LocationListener locationListener = new MyLocationListener();
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000, 10, locationListener);
and add onLocationChanged(Location loc) method that inside of it have your loc generate the longitude and latitude (String long = loc.getLongitude(); String lat = loc.getLatitude();)
and now use long, lat to generate your mapPath string and continue to generate the WebView
You can use this for ref: http://www.rdcworld-android.blogspot.in/2012/01/get-current-location-coordinates-city.html

Google maps android api v2 in fragment

Hy everyone.......
I've successfully got Google maps android API v2 working
but the google maps uses FragmentActivity for displaying map
i want to use fragment to display the map inside
currently i m using this code
#SuppressLint("NewApi")
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
try
{
setContentView(R.layout.maps);
map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
Marker hamburg = map.addMarker(new MarkerOptions()
.position(HAMBURG).title("Hamburg"));
Marker kiel = map.addMarker(new MarkerOptions()
.position(KIEL)
.title("Kiel")
.snippet("Kiel is cool")
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.ic_launcher)));
// Move the camera instantly to hamburg with a zoom of 15.
map.moveCamera(CameraUpdateFactory.newLatLngZoom(HAMBURG, 15));
// Zoom in, animating the camera.
map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
}
catch (Exception e)
{
// TODO Auto-generated catch block
Log.d("Error in Maps.class = " , e.toString());
}
}
but instead of extending from FragmentActivity i wanna extend from Fragment i.e displaying map inside a fragment
any help in this regard will be highly appreciated..
thanks in advance.......
If you have sucessfully installed the new maps V2 library then you should be able to just extend from "SupportMapFragment".
The Javadoc info is available here.
http://developer.android.com/reference/com/google/android/gms/maps/SupportMapFragment.html